$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
group_from_double_several_links.cc
1 // Copyright (C) 2009, 2010 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/labeling/colorize.hh>
31 #include <mln/value/label_16.hh>
32 #include <mln/core/alias/neighb2d.hh>
33 
34 #include <mln/io/pbm/load.hh>
35 #include <mln/io/ppm/save.hh>
36 
37 #include <mln/literal/colors.hh>
38 #include <mln/util/array.hh>
39 
40 #include <scribo/primitive/extract/components.hh>
41 #include <scribo/primitive/group/apply.hh>
42 #include <scribo/primitive/link/with_several_left_links.hh>
43 #include <scribo/primitive/link/with_several_right_links.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 int usage(const char *name)
52 {
53  std::cout << "Usage: " << name << " <input.pbm> " << std::endl;
54  return 1;
55 }
56 
57 
58 int main(int argc, char* argv[])
59 {
60  using namespace scribo;
61  using namespace mln;
62 
63  if (argc < 1)
64  return usage(argv[0]);
65 
66  scribo::make::internal::debug_filename_prefix = "group_with_double_several_links";
67 
68  image2d<bool> input;
69  io::pbm::load(input, argv[1]);
70 
71 
72  value::label_16 nbboxes;
73  typedef image2d<value::label_16> L;
74  std::cout << "extract bboxes" << std::endl;
76  comps = scribo::primitive::extract::components(input, c8(), nbboxes);
77 
78 
79  std::cout << "Remove small components" << std::endl;
80  comps = filter::components_small(comps, 4);
81 
82  std::cout << "Group with left link" << std::endl;
83  object_links<L> left_link
85 
86  std::cout << "Group with right link" << std::endl;
87  object_links<L> right_link
89 
90  std::cout << "BEFORE - nbboxes = " << nbboxes << std::endl;
91 
93  left_link,
94  right_link,
95  literal::red,
96  literal::cyan,
97  literal::yellow,
98  literal::green,
99  anchor::Center),
100  scribo::make::debug_filename("links.ppm"));
101 
102  // With validation.
103  std::cout << "Group from double link" << std::endl;
104 
105  object_groups<L> groups
106  = primitive::group::from_double_link(left_link, right_link);
107 
108  component_set<L> grouped_comps = primitive::group::apply(groups);
109 
111  grouped_comps.labeled_image(),
112  grouped_comps.nelements()),
113  scribo::make::debug_filename("label_color.ppm"));
114 
115  std::cout << "AFTER double grouping - nbboxes = " << grouped_comps.nelements() << std::endl;
116 
117  io::ppm::save(scribo::debug::bboxes_image(input, grouped_comps,
118  literal::red),
119  scribo::make::debug_filename("bboxes.ppm"));
120 
121 }