$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
group_from_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/value/label_16.hh>
30 #include <mln/io/ppm/save.hh>
31 #include <mln/io/pbm/load.hh>
32 #include <mln/core/alias/neighb2d.hh>
33 #include <mln/literal/colors.hh>
34 #include <mln/labeling/colorize.hh>
35 
36 #include <scribo/primitive/extract/objects.hh>
37 #include <scribo/primitive/link/with_graph.hh>
38 #include <scribo/primitive/group/from_graph.hh>
39 #include <scribo/primitive/group/apply.hh>
40 
41 #include <scribo/debug/save_bboxes_image.hh>
42 #include <scribo/debug/save_linked_bboxes_image.hh>
43 #include <scribo/make/debug_filename.hh>
44 
45 int usage(const char *name)
46 {
47  std::cout << "Usage: " << name << " <input.pbm> " << std::endl;
48  return 1;
49 }
50 
51 int main(int argc, char* argv[])
52 {
53  using namespace scribo;
54  using namespace mln;
55 
56  if (argc < 1)
57  return usage(argv[0]);
58 
59  scribo::make::internal::debug_filename_prefix = "group_with_graph";
60 
61  image2d<bool> input;
62  io::pbm::load(input, argv[1]);
63 
64  value::label_16 nbboxes;
65  typedef image2d<value::label_16> L;
66  typedef object_image(L) text_t;
67  text_t text = primitive::extract::objects(input, c8(), nbboxes);
68 
69  mln::util::graph g = primitive::link::with_graph(text, 255);
70 
71  std::cout << "BEFORE - nbboxes = " << nbboxes.next() << std::endl;
72  scribo::debug::save_linked_bboxes_image(input,
73  text, g,
74  literal::red, literal::cyan,
75  scribo::make::debug_filename("left_linked.ppm"));
76 // io::ppm::save(mln::labeling::colorize(value::rgb8(),
77 // text.label_image(),
78 // text.nlabels()),
79 // scribo::make::debug_filename("lbl_before.ppm"));
80 
81  object_groups<L> groups
82  = primitive::group::from_graph(text, g);
83 
84  text_t grouped_text = primitive::group::apply(text, groups);
85 
86  std::cout << "AFTER - nbboxes = " << grouped_text.bboxes().nelements() << std::endl;
87 
88  scribo::debug::save_bboxes_image(input, grouped_text.bboxes(),
89  literal::red,
90  scribo::make::debug_filename("grouped_text.ppm"));
91  io::ppm::save(mln::labeling::colorize(value::rgb8(),
92  grouped_text,
93  grouped_text.nlabels()),
94  scribo::make::debug_filename("label_color.ppm"));
95 
96 }