$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
labeled_image.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 <mln/core/image/image2d.hh>
27 #include <mln/core/image/imorph/labeled_image.hh>
28 #include <mln/core/routine/duplicate.hh>
29 #include <mln/make/image.hh>
30 #include <mln/make/box2d.hh>
31 #include <mln/value/label_8.hh>
32 #include <mln/accu/pair.hh>
33 #include <mln/accu/center.hh>
34 #include <mln/accu/shape/bbox.hh>
35 
36 
37 # include <mln/debug/println.hh>
38 
39 static const unsigned bboxes_1[][9] = { { 1,1, 1,1 }, // 1
40  { 2,2, 2,2 }, // 2
41  { 0,0, 0,0 },
42  { 0,0, 0,0 },
43  { 2,0, 2,1 }, // 5
44  { 0,0, 0,0 },
45  { 0,0, 0,0 },
46  { 0,0, 0,0 },
47  { 0,0, 0,1 } };
48 
49 
50 static const unsigned bboxes_2[][4] = { { 1,1, 1,1 },
51  { 2,2, 2,2 },
52  { 2,0, 2,1 },
53  { 0,0, 0,1 } };
54 
55 
56 
57 namespace mln
58 {
59 
60  template <typename I, unsigned n>
61  void test_image(const labeled_image<I>& lbl_i,
62  const unsigned bboxes[][n])
63  {
64  unsigned
65  j = 0,
66  k = 0;
67  for (unsigned i = 1; i <= lbl_i.nlabels(); ++i, ++j)
68  if (lbl_i.bbox(i).is_valid())
69  {
70  mln_assertion(lbl_i.bbox(i) == make::box2d(bboxes[j][0], bboxes[j][1],
71  bboxes[j][2], bboxes[j][3]));
72  ++k;
73  }
74 
75  mln_assertion(k == 4);
76  }
77 
78 } // end of namespace mln
79 
80 
81 
82 
83 int main()
84 {
85  using namespace mln;
86  using value::label_8;
87 
88 
89  label_8 lbl_values[][3] = { { 9, 9, 0 },
90  { 0, 1, 0 },
91  { 5, 5, 2 } };
92 
93  typedef image2d<label_8> lbl_t;
94  lbl_t lbl = make::image(lbl_values);
95 
96  labeled_image<lbl_t> lbl_i(lbl, 9);
97  mln_assertion(lbl_i.nlabels() == 9);
98  test_image(lbl_i, bboxes_1);
99 
100  fun::i2v::array<label_8> f(10, 0);
101  f(0) = 0;
102  f(1) = 1;
103  f(5) = 2;
104  f(9) = 5;
105  f(2) = 4;
106 
107  lbl_i.relabel(f);
108 
109  mln_assertion(lbl_i.nlabels() == 4);
110  test_image(lbl_i, bboxes_2);
111 }