$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dual_input_tree.cc
1 // Copyright (C) 2008, 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/image1d.hh>
27 #include <mln/core/alias/neighb1d.hh>
28 #include <mln/value/int_u8.hh>
29 
30 #include <mln/make/image.hh>
31 #include <mln/morpho/tree/dual_input_tree.hh>
32 
33 template <typename V, unsigned dim, unsigned dim2>
34 void test(V (&f_)[dim], V (&m_)[dim], V (&points_)[dim2], V (&p_)[dim2])
35 {
36  using namespace mln;
37  typedef image1d<V> I;
38  typedef p_array< mln_psite(I) > S;
39  typedef morpho::tree::data<I,S> tree_t;
40 
41 
42  I f = make::image(f_);
43  I m = make::image(m_);
44 
45 
46  tree_t tree = morpho::tree::dual_input_max_tree(f, m, c2());
47 
48  mln_dn_site_piter(tree_t) p(tree);
49  p.start();
50  for (unsigned i = 0; i < dim2; ++i, p.next())
51  {
52  mln_assertion(p.is_valid());
53  mln_assertion(p == point1d(points_[i]));
54  mln_assertion(tree.parent(p) == point1d(p_[i]));
55  }
56  mln_assertion(! p.is_valid());
57 }
58 
59 
60 
61 int main()
62 {
63 
64  using namespace mln;
65 
66  typedef value::int_u8 V;
67 
68  //V f_[] = {10, 10, 20, 20, 30, 30, 40, 40, 30, 30, 20, 20, 30, 30, 20, 20, 10, 20, 20, 10};
69  //V m_[] = {10, 10, 20, 20, 30, 30, 40, 40, 30, 30, 30, 30, 30, 30, 20, 20, 15, 15, 15, 15};
70 
71 
72  //V f_[] = {15, 15, 10, 10, 05, 05, 8, 8, 5, 5, 10, 10, 15, 15};
73  //V m_[] = {20, 20, 18, 18, 25, 25, 8, 8, 5, 5, 10, 10, 15, 15};
74 
75  {
76  V f[] = {15, 15, 15};
77  V m[] = {20, 20, 20};
78  V s[] = {0, 1, 2};
79  V p[] = {0, 0, 0};
80  test(f, m, s, p);
81  }
82 
83  {
84  V f[] = {15, 17, 17, 19, 16};
85  V m[] = {15, 17, 17, 19, 16};
86  V s[] = {0, 4, 1, 2, 3};
87  V p[] = {0, 0, 4, 1, 1};
88 
89 
90  test(f, m, s, p);
91  }
92 
93  {
94  V f[] = {15, 17, 17, 15, 18, 19};
95  V m[] = {15, 17, 17, 15, 18, 19};
96  V s[] = {0, 3, 1, 2, 4, 5};
97  V p[] = {0, 0, 0, 1, 0, 4};
98  test(f, m, s, p);
99  }
100 
101  // Clustering: simple connection
102  {
103  V f[] = {15, 17, 17, 15, 18, 19};
104  V m[] = {15, 18, 18, 18, 18, 19};
105  V s[] = {0, 3, 1, 2, 4, 5};
106  V p[] = {0, 0, 0, 1, 1, 4};
107  test(f, m, s, p);
108  }
109 
110  // Clustering: merge two nodes
111  {
112  V f[] = {15, 18, 18, 15, 18, 19};
113  V m[] = {15, 18, 18, 18, 18, 19};
114  V s[] = {0, 3, 1, 2, 4, 5};
115  V p[] = {0, 0, 0, 1, 1, 1};
116  test(f, m, s, p);
117  }
118 
119  // Clustering: create new node
120  {
121  V f[] = {18, 15, 18};
122  V m[] = {18, 17, 18};
123  V s[] = {1, 4, 0, 2};
124  V p[] = {1, 1, 4, 4};
125  test(f, m, s, p);
126  }
127 
128  // Clustering: create new node
129  {
130  V f[] = {10, 10, 12, 12};
131  V m[] = {11, 11, 13, 13};
132  V s[] = {0, 1, 4, 2, 3};
133  V p[] = {0, 0, 0, 4, 2};
134  test(f, m, s, p);
135  }
136 
137  // Segmentation: simple (no node creation)
138  {
139  V f[] = {8, 10, 10, 12, 12};
140  V m[] = {8, 8, 8, 12, 12};
141  V s[] = {0, 1, 2, 3, 4};
142  V p[] = {0, 0, 0, 0, 3};
143  test(f, m, s, p);
144  }
145 
146  // Segmentation: simple (no node creation)
147  {
148  V f[] = {8, 10, 10, 8};
149  V m[] = {8, 8, 8, 8};
150  V s[] = {0, 3, 1, 2};
151  V p[] = {0, 0, 0, 0};
152  test(f, m, s, p);
153  }
154 
155  // Segmentation: create node
156  {
157  V f[] = {8, 10, 10, 8};
158  V m[] = {8, 9, 9, 8};
159  V s[] = {0, 3, 5, 1, 2};
160  V p[] = {0, 0, 0, 5, 5};
161  test(f, m, s, p);
162  }
163 
164  // Segmentation: create a root node
165  {
166  V f[] = {8, 10, 10, 8};
167  V m[] = {8, 5, 9, 8};
168  V s[] = {5, 0, 3, 1, 6, 2}; // Or {5, 0, 3, 6, 1, 2} for a strict sort
169  V p[] = {5, 5, 5, 5, 3, 6};
170  test(f, m, s, p);
171  }
172 
173 }