File: normalize.ml

package info (click to toggle)
camlimages 2.20-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,020 kB
  • ctags: 2,432
  • sloc: ml: 12,244; ansic: 2,402; makefile: 1,135; sh: 193
file content (53 lines) | stat: -rw-r--r-- 1,742 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(***********************************************************************)
(*                                                                     *)
(*                           Objective Caml                            *)
(*                                                                     *)
(*            Jun Furuse, projet Cristal, INRIA Rocquencourt           *)
(*                                                                     *)
(*  Copyright 1999-2004,                                               *)
(*  Institut National de Recherche en Informatique et en Automatique.  *)
(*  Distributed only by permission.                                    *)
(*                                                                     *)
(***********************************************************************)

(* $Id: normalize.ml,v 1.7 2004/09/24 10:55:10 weis Exp $ *)

open Images;;
open OImages;;
open Info;;

let files = ref [] in
Arg.parse []
  (fun s -> files := s :: !files)
  "normalize src dst";

let src, dst =
  match List.rev !files with
  | [src; dst] -> src, dst
  | _ -> assert false in

let src = OImages.rgb24 (OImages.load src []) in

let normalize img =
  (* Make monochrome *)
  let hist = Colorhist.create () in
  for x = 0 to src#width - 1 do
    for y = 0 to src#height - 1 do
      Colorhist.store_sample hist (src#get x y)
    done
  done;
  prerr_endline "histogram done";
  let normalizer = Colorhist.normalize 0.9 hist in
  prerr_endline "normalizer done";
  for x = 0 to src#width - 1 do
    for y = 0 to src#height - 1 do
      let rgb = src#get x y in
      let new_rgb = normalizer rgb in
      src#set x y new_rgb;
    done
  done in

let saver img = img#save dst None [] in

normalize src;
saver src;;