$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
group_from_double_link.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 <iostream>
28 
29 #include <mln/core/image/image2d.hh>
30 #include <mln/labeling/colorize.hh>
31 #include <mln/debug/println.hh>
32 #include <mln/util/array.hh>
33 #include <mln/literal/colors.hh>
34 #include <mln/io/pbm/load.hh>
35 #include <mln/core/alias/neighb2d.hh>
36 #include <mln/value/label_16.hh>
37 
38 #include <scribo/core/object_links.hh>
39 
40 #include <scribo/primitive/extract/components.hh>
41 #include <scribo/primitive/group/apply.hh>
42 #include <scribo/primitive/link/with_single_left_link.hh>
43 #include <scribo/primitive/link/with_single_right_link.hh>
44 #include <scribo/debug/linked_bboxes_image.hh>
45 #include <scribo/primitive/group/from_double_link.hh>
46 #include <scribo/filter/objects_small.hh>
47 
48 #include <scribo/debug/bboxes_image.hh>
49 #include <scribo/make/debug_filename.hh>
50 
51 
52 #include <scribo/debug/usage.hh>
53 
54 const char *args_desc[][2] =
55 {
56  { "input.pbm", "A binary image. 'True' for objects, 'False' for the "
57  "background." },
58  { "hlmax", "Maximum distance between two grouped objects while browsing "
59  "on the left." },
60  { "hrmax", "Maximum distance between two grouped objects while browsing "
61  "on the right." },
62  { "prefix", "Output names prefix" },
63  {0, 0}
64 };
65 
66 int main(int argc, char *argv[])
67 {
68  using namespace scribo;
69  using namespace mln;
70 
71  if (argc != 5)
72  return scribo::debug::usage(argv,
73  "Group potential text objects using a double"
74  "validation link.",
75  "input.pbm hlmax hrmax prefix",
76  args_desc);
77 
78 
79  scribo::make::internal::debug_filename_prefix = argv[4];
80 
81  image2d<bool> input;
82  io::pbm::load(input, argv[1]);
83 
84  value::label_16 nbboxes;
85  typedef image2d<value::label_16> L;
87  text = primitive::extract::components(input, c8(), nbboxes);
88 
89  text = filter::components_small(text, 4);
90 
91  object_links<L> left_link
92  = primitive::link::with_single_left_link(text, atoi(argv[2]));
93  object_links<L> right_link
94  = primitive::link::with_single_right_link(text, atoi(argv[3]));
95 
96  std::cout << "BEFORE - nbboxes = " << nbboxes << std::endl;
97 
99  left_link, right_link,
100  literal::red,
101  literal::cyan,
102  literal::yellow,
103  literal::green,
104  anchor::MassCenter),
105  scribo::make::debug_filename("links.ppm"));
106 
107  // With validation.
108  object_groups<L> groups
109  = primitive::group::from_double_link(left_link, right_link);
110 
111  component_set<L> grouped_text = primitive::group::apply(groups);
112 
114  grouped_text.labeled_image(),
115  grouped_text.nelements()),
116  scribo::make::debug_filename("label_color.ppm"));
117 
118  std::cout << "AFTER double grouping - nbboxes = "
119  << grouped_text.nelements() << std::endl;
120 
121  io::ppm::save(scribo::debug::bboxes_image(input, grouped_text,
122  literal::red),
123  scribo::make::debug_filename("bboxes.ppm"));
124 
125 }