$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
group_from_several_graph.cc
1 // Copyright (C) 2009 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 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #include <iostream>
27 
28 #include <mln/core/image/image2d.hh>
29 #include <mln/core/alias/neighb2d.hh>
30 
31 #include <mln/literal/colors.hh>
32 #include <mln/util/graph.hh>
33 
34 #include <mln/labeling/colorize.hh>
35 
36 #include <mln/value/rgb8.hh>
37 #include <mln/value/label_16.hh>
38 
39 #include <mln/io/pbm/load.hh>
40 #include <mln/io/ppm/save.hh>
41 
42 #include <scribo/core/object_groups.hh>
43 #include <scribo/primitive/extract/objects.hh>
44 #include <scribo/primitive/link/with_several_graphes.hh>
45 #include <scribo/primitive/group/from_graph.hh>
46 #include <scribo/primitive/group/apply.hh>
47 
48 #include <scribo/debug/save_bboxes_image.hh>
49 #include <scribo/debug/save_linked_bboxes_image.hh>
50 #include <scribo/make/debug_filename.hh>
51 
52 int usage(const char *name)
53 {
54  std::cout << "Usage: " << name << " <input.pbm> " << std::endl;
55  return 1;
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_several_graph";
67 
68  image2d<bool> input;
69  io::pbm::load(input, argv[1]);
70 
71  value::label_16 nbboxes;
72  typedef image2d<value::label_16> L;
73  typedef object_image(L) text_t;
74  text_t text = scribo::primitive::extract::objects(input, c8(), nbboxes);
75 
76  mln::util::graph g = primitive::link::with_several_graphes(text, 128);
77 
78  std::cout << "BEFORE - nbboxes = " << nbboxes.next() << std::endl;
79  scribo::debug::save_linked_bboxes_image(input,
80  text, g,
81  literal::red, literal::cyan,
82  scribo::make::debug_filename("left_linked.ppm"));
83 
84  object_groups<L> groups = primitive::group::from_graph(text, g);
85 
86  text_t grouped_text = primitive::group::apply(text, groups);
87 
88  std::cout << "AFTER - nbboxes = " << grouped_text.bboxes().nelements() << std::endl;
89 
90  scribo::debug::save_bboxes_image(input, grouped_text.bboxes(),
91  literal::red,
92  scribo::make::debug_filename("grouped_text.ppm"));
93  io::ppm::save(mln::labeling::colorize(value::rgb8(),
94  grouped_text,
95  grouped_text.nlabels()),
96  scribo::make::debug_filename("label_color.ppm"));
97 
98 }