$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
object_groups.cc
1 // Copyright (C) 2011, 2014 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 
27 
28 #include <mln/core/image/image2d.hh>
29 #include <mln/core/alias/neighb2d.hh>
30 #include <mln/io/pbm/load.hh>
31 
32 #include <scribo/core/component_set.hh>
33 #include <scribo/core/def/lbl_type.hh>
34 #include <scribo/core/object_links.hh>
35 #include <scribo/core/object_groups.hh>
36 #include <scribo/primitive/extract/components.hh>
37 #include <scribo/primitive/link/with_single_left_link.hh>
38 
39 #include "tests/data.hh"
40 
41 int main()
42 {
43  using namespace mln;
44  using namespace scribo;
45 
46  std::string img = SCRIBO_IMG_DIR "/the_valleys.pbm";
47 
48  static const unsigned comp_to_group_ref[] =
49  { 0, 1, 4, 2, 3, 2, 2, 4, 4, 2, 2, 2, 2 };
50  static const unsigned pixel_area_ref[] = { 0, 3, 973, 39, 426 };
51  static const box2d bbox_ref[] = {
52  box2d(),
53  make::box2d(0,91, 1,92),
54  make::box2d(9,95, 45,224),
55  make::box2d(9,204, 20,209),
56  make::box2d(9,12, 36,64)
57  };
58 
59  static const unsigned comp_ids_count_ref[] = { 0, 1, 7, 1, 3 };
60  static const int comp_ids_ref[][7] = {
61  { 0, 0, 0, 0, 0, 0, 0 },
62  { 1, 0, 0, 0, 0, 0, 0 },
63  { 3, 9, 5, 6, 10, 11, 12 },
64  { 4, 0, 0, 0, 0, 0, 0 },
65  { 7, 2, 8, 0, 0, 0, 0 } };
66 
67  image2d<bool> input;
68  io::pbm::load(input, img.c_str());
69 
70  typedef scribo::def::lbl_type V;
71  V nlabels;
72  typedef image2d<V> L;
74  comps = scribo::primitive::extract::components(input, c8(), nlabels);
75 
76  object_links<L> link
77  = primitive::link::with_single_left_link(comps, 30);
78 
79  object_groups<L> group(link);
80 
81  mln_assertion(group.nelements() == 5);
82  mln_assertion(group.comp_to_group().nelements() == 13);
83 
84  // Checking comp_to_group()
85  for (unsigned i = 0; i < group.comp_to_group().nelements(); ++i)
86  mln_assertion(group.comp_to_group()[i] == comp_to_group_ref[i]);
87 
88  // Checking group info data.
89  for_all_groups(g, group)
90  {
91  mln_assertion(group(g).id() == g);
92  mln_assertion(group(g).is_valid());
93  mln_assertion(group(g).pixel_area() == pixel_area_ref[g]);
94  mln_assertion(group(g).bbox() == bbox_ref[g]);
95  mln_assertion(group(g).component_ids().nelements()
96  == comp_ids_count_ref[g]);
97 
98  for_all_elements(e, group(g).component_ids())
99  mln_assertion(group(g).component_ids()[e] == comp_ids_ref[g][e]);
100  }
101 
102  // Checking group_of()
103  for_all_comps(c, comps)
104  mln_assertion(group.group_of(c).id() == comp_to_group_ref[c]);
105 }