$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
sauvola_debug.cc
1 // Copyright (C) 2009, 2010, 2011 EPITA Research and Development
2 // Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #include <mln/io/magick/load.hh>
28 #include <mln/io/pbm/save.hh>
29 #include <mln/io/pgm/save.hh>
30 
31 #include <mln/data/stretch.hh>
32 #include <mln/data/convert.hh>
33 #include <mln/data/saturate.hh>
34 
35 #include <mln/fun/v2v/rgb_to_luma.hh>
36 
37 #include <scribo/binarization/local_threshold.hh>
38 #include <scribo/binarization/sauvola.hh>
39 #include <scribo/debug/usage.hh>
40 
41 const char *args_desc[][2] =
42 {
43  { "input.*", "An image." },
44  { "output.pbm", "A binary image." },
45  { "mean.pgm", "The local mean image." },
46  { "stddev.pgm", "The local standard deviation image." },
47  { "threshold.pgm", "Threshold image." },
48  { "alpham.pgm", "alpha * m values" },
49  { "alphacond.pbm", "Boolean image. True if s < (alpha * m / 2)" },
50 
51  { "mean_factor", "Mean value factor (default 1)." },
52  { "stddev_factor", "Standard deviation value factor (default 2)." },
53  { "alphamfact", "" },
54 
55  { "w", "Window size (default 101)." },
56  { "k", "Sauvola's formulae parameter (default 0.34)." },
57  {0, 0}
58 };
59 
60 
61 int main(int argc, char *argv[])
62 {
63  using namespace mln;
64  using namespace scribo::binarization;
65 
66  if (argc < 5 || argc >= 13)
67  return scribo::debug::usage(argv,
68  "Binarization based on Sauvola's algorithm.",
69  "input.* output.pbm mean.pgm stddev.pgm threshold.pgm alpham.pgm "
70  "alphacond.pbm <mean_factor> <stddev_factor> <alphamfact> <w> <k>",
71  args_desc);
72 
73  mln_trace("main");
74 
75  unsigned w;
76  if (argc >= 12)
77  w = atoi(argv[11]);
78  else
79  w = 101;
80 
81  double k;
82  if (argc >= 13)
83  k = atof(argv[12]);
84  else
85  k = 0.34f;
86 
87  std::cout << "Using w=" << w << " and k=" << k << std::endl;
88 
89  if (argc >= 4)
90  scribo::binarization::internal::mean_image_output = argv[3];
91  if (argc >= 5)
92  scribo::binarization::internal::stddev_image_output = argv[4];
93  if (argc >= 6)
94  scribo::binarization::internal::threshold_image_output = argv[5];
95  if (argc >= 7)
96  scribo::binarization::internal::alpham_image_output = argv[6];
97  if (argc >= 8)
98  scribo::binarization::internal::alphacond_image_output = argv[7];
99 
100  if (argc >= 9)
101  scribo::binarization::internal::mean_debug_factor = atof(argv[8]);
102  else
103  scribo::binarization::internal::mean_debug_factor = 1;
104  if (argc >= 10)
105  scribo::binarization::internal::stddev_debug_factor = atof(argv[9]);
106  else
107  scribo::binarization::internal::stddev_debug_factor = 2;
108  if (argc >= 11)
109  scribo::binarization::internal::alpham_debug_factor = atof(argv[10]);
110  else
111  scribo::binarization::internal::alpham_debug_factor = 2;
112 
113  image2d<value::rgb8> input;
114  io::magick::load(input, argv[1]);
115 
116 
118  gima = data::transform(input,
120 
121 
123  out = scribo::binarization::sauvola(gima, w, k);
124 
125 
126  io::pbm::save(out, argv[2]);
127 
128 
129 //io::pgm::save(data::saturate(value::int_u8(), thres), "thres_saturated.pgm");
130 
131 }