$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
show_stoppers.cc
1 // Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 
17 #include <mln/core/image/image2d.hh>
18 #include <mln/core/alias/box2d.hh>
19 #include <mln/core/alias/neighb2d.hh>
20 #include <mln/io/pbm/all.hh>
21 #include <mln/arith/plus.hh>
22 #include <mln/labeling/foreground.hh>
23 
24 #include <scribo/primitive/extract/lines_h_pattern.hh>
25 #include <scribo/primitive/extract/lines_v_pattern.hh>
26 #include <scribo/primitive/extract/separators_nonvisible.hh>
27 #include <scribo/debug/usage.hh>
28 #include <scribo/debug/bboxes_image.hh>
29 #include <scribo/core/document.hh>
30 #include <scribo/core/def/lbl_type.hh>
31 
32 #include <scribo/io/xml/save.hh>
33 
34 const char *args_desc[][2] =
35 {
36  { "length", " Minimum line length. (default: 101)" },
37  { "delta", " Distance between the object pixel and the background pixel"
38  "(default: 4)" },
39  {0, 0}
40 };
41 
42 
43 int main(int argc, char *argv[])
44 {
45  using namespace mln;
46 
47  if (argc != 8 && argc != 6)
48  return scribo::debug::usage(argv,
49  "Extract horizontal, vertical lines and stoppers",
50  "input.pbm out_seps.pbm out_in_wo_seps.pbm "
51  "out_seps_bbox.ppm out_visible_seps.pbm length delta",
52  args_desc);
53 
54  mln_trace("main");
55 
56  image2d<bool> input;
57  io::pbm::load(input, argv[1]);
58 
59  // Set default option value
60  unsigned
61  length = 101,
62  delta = 4;
63  if (argc > 6)
64  {
65  length = atoi(argv[6]);
66  delta = atoi(argv[7]);
67  }
68 
69  util::timer t;
70 
71  t.start();
73  h_lines = scribo::primitive::extract::lines_h_pattern(input, length,
74  delta);
75 
77  v_lines = scribo::primitive::extract::lines_v_pattern(input, length,
78  delta);
79 
80  v_lines += h_lines;
81 
82  t.stop();
83 
84  // Save input without separators
85  {
86  image2d<bool> in_wo_seps = duplicate(input);
87  data::fill((in_wo_seps | pw::value(v_lines)).rw(), false);
88  io::pbm::save(in_wo_seps, argv[3]);
89  }
90 
91  // Save bbox image
92  value::int_u8 nlabels;
93  image2d<value::int_u8> lbl = labeling::foreground(v_lines, c4(), nlabels);
95  bbox = labeling::compute(accu::shape::bbox<point2d>(), lbl, nlabels);
97  argv[4]);
98 
99  // Save visible separators
100  mln::io::pbm::save(v_lines, argv[5]);
101 
102  t.resume();
103 
104  // Non visible separators
107 
108  t.stop();
109  std::cout << t << "s" << std::endl;
110 
111  // // Saving stoppers data to XML
112  // typedef image2d<scribo::def::lbl_type> L;
113  // scribo::document<L> doc(argv[1]);
114  // doc.open();
115  // doc.set_whitespace_separators(nonvisible);
116  // doc.set_line_separators(v_lines);
117  // scribo::io::xml::save(doc, argv[5], scribo::io::xml::Full);
118 
119  // Save binary image.
120  v_lines += nonvisible;
121  mln::io::pbm::save(v_lines, argv[2]);
122 
123 }