$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
show_links_left_right_links_validation.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/debug/println.hh>
32 #include <mln/data/convert.hh>
33 #include <mln/util/array.hh>
34 #include <mln/literal/colors.hh>
35 #include <mln/io/pbm/load.hh>
36 #include <mln/io/ppm/save.hh>
37 #include <mln/core/alias/neighb2d.hh>
38 #include <mln/value/label_16.hh>
39 
40 #include <scribo/core/object_links.hh>
41 
42 #include <scribo/primitive/extract/components.hh>
43 
44 #include <scribo/primitive/link/with_single_left_link.hh>
45 #include <scribo/primitive/link/with_single_right_link.hh>
46 #include <scribo/primitive/link/merge_double_link.hh>
47 
48 #include <scribo/draw/bounding_boxes.hh>
49 #include <scribo/draw/bounding_box_links.hh>
50 
51 #include <scribo/debug/usage.hh>
52 
53 
54 
55 const char *args_desc[][2] =
56 {
57  { "input.pbm", "A binary image. 'True' for objects, 'False'\
58 for the background." },
59  { "hlmax", "Maximum distance between two grouped objects while browsing on the left." },
60  { "hrmax", "Maximum distance between two grouped objects while browsing on the right." },
61  {0, 0}
62 };
63 
64 int main(int argc, char *argv[])
65 {
66  using namespace scribo;
67  using namespace mln;
68 
69  if (argc != 5)
70  return scribo::debug::usage(argv,
71  "Display double validated (left and right) links between objects",
72  "<input.pbm> <hlmax> <hrmax> <output.ppm>",
73  args_desc);
74 
75  image2d<bool> input;
76  io::pbm::load(input, argv[1]);
77 
78  // Finding objects.
79  value::label_16 nbboxes;
80  typedef image2d<value::label_16> L;
81  component_set<L> comps = primitive::extract::components(input, c8(), nbboxes);
82 
83  // Left links.
84  object_links<L> left_link
85  = primitive::link::with_single_left_link(comps, atoi(argv[2]));
86 
87  // Right links.
88  object_links<L> right_link
89  = primitive::link::with_single_right_link(comps, atoi(argv[3]));
90 
91  // Validation.
93  links = primitive::link::merge_double_link(left_link, right_link);
94 
95 
96  // Saving result.
97  image2d<value::rgb8> output = data::convert(value::rgb8(), input);
98 
100  links,
101  literal::green, anchor::MassCenter);
102 
103  util::array<bool> drawn(unsigned(comps.nelements()) + 1, 0);
104  for_all_comps(i, comps)
105  if (links(i) == i && ! drawn(i))
106  {
107  mln::draw::box(output, comps(i).bbox(), literal::orange);
108  drawn[i] = true;
109  }
110  else
111  {
112  mln::draw::box(output, comps(i).bbox(), literal::blue);
113  mln::draw::box(output, comps(links(i)).bbox(), literal::blue);
114  drawn[i] = true;
115  drawn[links(i)] = true;
116  }
117 
118  io::ppm::save(output, argv[4]);
119 }