noureddine_ms a écrit :
> hi all
> has any one used camlimages for binarizing images?
> if so, can u provide us with guidelines please
>
> thx
not done with camlimages but with ocaml-imagemagick:
------ (usage) ------
ocaml binarize-image.ml <image> <threshold
level> [blur]
threshold level: a percentage (between 0.0 and 1.0)
blur: optional argument
example:
ocaml binarize-image.ml ~/gnuart/1-006.png 0.3 0.7
----------
------ (binarize-image.ml) ------
#! /usr/bin/env ocaml
#directory "+libMagick"
#load "magick.cma"
open Magick
open Imper
let binarize_image ~filename ~percent ?(do_blur=0.0) () =
let img = read_image ~filename in
let p = 65535. *. percent in
let level = (truncate(p +. 0.5)) in
(* you can modify this part to get thresholding
differently
along each channel *)
let red_lvl, green_lvl, blue_lvl = level, level, level in
let threshold = Printf.sprintf "%d,%d,%d"
red_lvl green_lvl blue_lvl in
(* applying a small blur, removes noisy details *)
if do_blur <> 0.0 then
blur img ~sigma:do_blur ();
black_threshold img ~threshold;
white_threshold img ~threshold;
(img)
;;
let () =
let argc = Array.length Sys.argv in
let filename = Sys.argv.(1)
and percent = float_of_string Sys.argv.(2)
and do_blur = if argc = 4 then float_of_string
Sys.argv.(3) else 0.0
in
let img = binarize_image ~filename ~percent ~do_blur ()
in
display img; (* show the result *)
(* add the prefix "bin_" to the saved image *)
let bin_file =
let dir = (Filename.dirname filename)
and file = "bin_" ^ (Filename.basename
filename)
in
Filename.concat dir file
in
write_image img ~filename:bin_file;
;;
----------
Depending of what your trying to do there could be other
imagemagick filters
you may prefer to use. For exemple instead of blur there are
filters that
only blur pixels in the same color area. There are also
different threshold
filters.
--
Archives up to December 31, 2007 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
The archives of the very official ocaml list (the seniors'
one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid
flames etc.
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http:/
/groups.yahoo.com/group/ocaml_beginners/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
ht
tp://groups.yahoo.com/group/ocaml_beginners/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:ocaml_beginners-digest@yahoogroups.com
mailto:ocaml_beginners-fullfeatured@yahoogroups.com
<*> To unsubscribe from this group, send an email to:
ocaml_beginners-unsubscribe@yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.c
om/info/terms/
|