$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
show_separators.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/io/ppm/save.hh>
22 #include <mln/arith/plus.hh>
23 #include <mln/labeling/foreground.hh>
24 #include <mln/labeling/compute.hh>
25 
26 #include <scribo/primitive/extract/lines_h_pattern.hh>
27 #include <scribo/primitive/extract/lines_v_pattern.hh>
28 #include <scribo/debug/usage.hh>
29 #include <scribo/debug/bboxes_image.hh>
30 
31 
32 const char *args_desc[][2] =
33 {
34  { "length", " Minimum line length. (default: 101)" },
35  { "delta", " Distance between the object pixel and the background pixel"
36  "(default: 4)" },
37  {0, 0}
38 };
39 
40 
41 int main(int argc, char *argv[])
42 {
43  using namespace mln;
44 
45  if (argc != 7 && argc != 5)
46  return scribo::debug::usage(argv,
47  "Extract horizontal and vertical lines patterns",
48  "input.pbm output.pbm input_wo_seps.pbm output.ppm length delta",
49  args_desc);
50 
51  mln_trace("main");
52 
53  image2d<bool> input;
54  io::pbm::load(input, argv[1]);
55 
56  // Set default option value
57  unsigned
58  length = 101,
59  delta = 4;
60  if (argc > 5)
61  {
62  length = atoi(argv[5]);
63  delta = atoi(argv[6]);
64  }
65 
66  util::timer t;
67  t.start();
68 
70  h_lines = scribo::primitive::extract::lines_h_pattern(input, length, delta);
71 
73  v_lines = scribo::primitive::extract::lines_v_pattern(input, length, delta);
74 
75  v_lines += h_lines;
76 
77  t.stop();
78  /* FIXME: Help the compiler to ``unproxy' the float stored in the
79  timer. There is a problem with an overload resolution of
80  `mln::unproxy_rec' here. */
81  std::cout << t.read() << "s" << std::endl;
82 
83  // Save binary image.
84  io::pbm::save(v_lines, argv[2]);
85 
86  // Save input without separators
87  {
88  image2d<bool> in_wo_seps = duplicate(input);
89  data::fill((in_wo_seps | pw::value(v_lines)).rw(), false);
90  io::pbm::save(in_wo_seps, argv[3]);
91  }
92 
93  // Save bbox image
94  value::int_u8 nlabels;
95  image2d<value::int_u8> lbl = labeling::foreground(v_lines, c4(), nlabels);
97  bbox = labeling::compute(accu::shape::bbox<point2d>(), lbl, nlabels);
99 
100 }