$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
show_lines_boldness.cc
1 // Copyright (C) 2011, 2012 EPITA Research and Development Laboratory
2 // (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 <iostream>
28 
29 #include <mln/core/image/image2d.hh>
30 #include <mln/io/pbm/load.hh>
31 #include <mln/value/int_u16.hh>
32 #include <mln/draw/box_plain.hh>
33 #include <mln/pw/all.hh>
34 #include <mln/core/image/dmorph/image_if.hh>
35 #include <mln/data/convert.hh>
36 #include <mln/literal/colors.hh>
37 #include <mln/math/round.hh>
38 
39 #include <scribo/debug/usage.hh>
40 
41 #include <scribo/core/component_set.hh>
42 #include <scribo/core/object_links.hh>
43 #include <scribo/core/object_groups.hh>
44 
45 #include <scribo/text/extract_lines_with_features.hh>
46 #include <scribo/estim/components_features.hh>
47 
48 #include <scribo/io/xml/save.hh>
49 
50 
51 const char *args_desc[][2] =
52 {
53  {0, 0}
54 };
55 
56 
57 
58 int main(int argc, char* argv[])
59 {
60  using namespace scribo;
61  using namespace mln;
62 
63  if (argc != 3)
64  return scribo::debug::usage(argv,
65  "Show text lines",
66  "input.pbm out_prefix",
67  args_desc);
68 
69  mln_trace("main");
70 
71  image2d<bool> input;
72  mln::io::pbm::load(input, argv[1]);
73 
74  std::string prefix = argv[2];
75 
77  typedef value::int_u8 V;
78 
79  // Extract lines
82  data::convert(value::rgb8(), input), input, c8());
83  const component_set<L>& comp_set = lines.components();
84 
85  // Min boldness / line
86  {
87  image2d<V> min_boldness;
88  initialize(min_boldness, input);
89 
90  data::fill(min_boldness, 0);
91  for_all_lines(l, lines)
92  if (lines(l).is_textline())
93  {
94  float min = 65000;
95 
96  // Compute min
97  for_all_line_comps(cid, lines(l).component_ids())
98  {
99  unsigned id = lines(l).component_ids()(cid);
100  if (comp_set(id).features().boldness < min)
101  min = comp_set(id).features().boldness;
102  }
103 
104  // Draw
105  for_all_line_comps(cid, lines(l).component_ids())
106  {
107  unsigned id = lines(l).component_ids()(cid);
108  data::fill(((min_boldness | comp_set(id).bbox()).rw()
109  | (pw::value(comp_set.labeled_image()) == pw::cst(id))).rw(),
110  mln::math::round<V>(min));
111  }
112 
113  }
114 
115  mln::io::pgm::save(min_boldness, prefix + "_min_boldness.pgm");
116  }
117 
118  // Max boldness / line
119  {
120  image2d<V> max_boldness;
121  initialize(max_boldness, input);
122 
123  data::fill(max_boldness, 0);
124  for_all_lines(l, lines)
125  if (lines(l).is_textline())
126  {
127  float max = 65000;
128 
129  // Compute max
130  for_all_line_comps(cid, lines(l).component_ids())
131  {
132  unsigned id = lines(l).component_ids()(cid);
133  if (comp_set(id).features().boldness < max)
134  max = comp_set(id).features().boldness;
135  }
136 
137  // Draw
138  for_all_line_comps(cid, lines(l).component_ids())
139  {
140  unsigned id = lines(l).component_ids()(cid);
141  data::fill(((max_boldness | comp_set(id).bbox()).rw()
142  | (pw::value(comp_set.labeled_image()) == pw::cst(id))).rw(),
143  mln::math::round<V>(max));
144  }
145 
146  }
147 
148  mln::io::pgm::save(max_boldness, prefix + "_max_boldness.pgm");
149  }
150 
151 
152  // Mean boldness / line
153  {
154  image2d<V> min_boldness;
155  initialize(min_boldness, input);
156 
157  data::fill(min_boldness, 0);
158  for_all_lines(l, lines)
159  if (lines(l).is_textline())
160  {
161  // Draw
162  for_all_line_comps(cid, lines(l).component_ids())
163  {
164  unsigned id = lines(l).component_ids()(cid);
165  data::fill(((min_boldness | comp_set(id).bbox()).rw()
166  | (pw::value(comp_set.labeled_image()) == pw::cst(id))).rw(),
167  mln::math::round<V>(lines(l).boldness()));
168  }
169 
170  }
171 
172  mln::io::pgm::save(min_boldness, prefix + "_mean_boldness.pgm");
173  }
174 
175  // Stddev boldness / line
176  {
177  image2d<V> min_boldness;
178  initialize(min_boldness, input);
179 
180  data::fill(min_boldness, 0);
181  for_all_lines(l, lines)
182  if (lines(l).is_textline())
183  {
184  // Draw
185  for_all_line_comps(cid, lines(l).component_ids())
186  {
187  unsigned id = lines(l).component_ids()(cid);
188  data::fill(((min_boldness | comp_set(id).bbox()).rw()
189  | (pw::value(comp_set.labeled_image()) == pw::cst(id))).rw(),
190  mln::math::round<V>(lines(l).boldness_reliability()));
191  }
192 
193  }
194 
195  mln::io::pgm::save(min_boldness, prefix + "_stddev_boldness.pgm");
196  }
197 
198 
199 }
200