$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
general.cc
1 // Copyright (C) 2007, 2008, 2009, 2010 EPITA Research and Development
2 // Laboratory (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 <mln/core/image/image2d.hh>
28 #include <mln/value/int_u8.hh>
29 #include <mln/io/pgm/load.hh>
30 #include <mln/io/pbm/load.hh>
31 
32 #include <mln/win/all.hh>
33 #include <mln/morpho/erosion.hh>
34 #include <mln/morpho/dilation.hh>
35 
36 #include "tests/data.hh"
37 
38 
39 int main()
40 {
41  using namespace mln;
42  using value::int_u8;
43 
44 
45  // Windows.
46  win::rectangle2d rec(5, 5);
47  win::hline2d hline(7);
48  win::vline2d vline(7);
49  win::diag2d diag2d(7);
50  win::backdiag2d backdiag2d(7);
51  win::octagon2d oct(2 * 3 + 1);
52 
53  morpho::erosion_op ero;
54  morpho::dilation_op dil;
55 
56  {
57  image2d<int_u8> lena, out, ref;
58  io::pgm::load(lena, MLN_IMG_DIR "/small.pgm");
59 
60 
61  // Rectangle (erosion).
62 
63  ref = morpho::impl::generic::general_on_function(ero, lena, rec);
64 
65  out = morpho::impl::general_rectangle2d(ero, lena, rec);
66  mln_assertion(out == ref);
67 
68  out = morpho::impl::general_arbitrary_2d(ero, lena, rec);
69  mln_assertion(out == ref);
70 
71  out = morpho::impl::general_directional(ero, lena, rec, 0);
72  mln_assertion(out == ref);
73 
74  out = morpho::impl::general_directional(ero, lena, rec, 1);
75  mln_assertion(out == ref);
76 
77 
78  // Rectangle (dilation).
79 
80  ref = morpho::impl::generic::general_on_function(dil, lena, rec);
81 
82  out = morpho::impl::general_rectangle2d(dil, lena, rec);
83  mln_assertion(out == ref);
84 
85  out = morpho::impl::general_arbitrary_2d(dil, lena, rec);
86  mln_assertion(out == ref);
87 
88  out = morpho::impl::general_directional(dil, lena, rec, 0);
89  mln_assertion(out == ref);
90 
91  out = morpho::impl::general_directional(dil, lena, rec, 1);
92  mln_assertion(out == ref);
93 
94 
95  // Hline.
96  ref = morpho::impl::generic::general_on_function(ero, lena, hline);
97 
98  out = morpho::impl::general_directional(ero, lena, hline, 1);
99  mln_assertion(out == ref);
100 
101  out = morpho::impl::general_line(ero, lena, hline);
102  mln_assertion(out == ref);
103 
104 
105  // Vline.
106  ref = morpho::impl::generic::general_on_function(ero, lena, vline);
107 
108  out = morpho::impl::general_directional(ero, lena, vline, 0);
109  mln_assertion(out == ref);
110 
111  out = morpho::impl::general_line(ero, lena, vline);
112  mln_assertion(out == ref);
113 
114  /*
115 
116  // Diag2d.
117  ref = morpho::impl::generic::erosion_on_function(lena, diag2d);
118 
119  // Backdiag2d.
120  ref = morpho::impl::generic::erosion_on_function(lena, backdiag2d);
121 
122  // Octagon
123  ref = morpho::impl::generic::erosion_on_function(lena, oct);
124  // io::pgm::save(ref, "general-out_oct_ref.pgm");
125 
126  */
127  }
128 
129 
130  /*
131 
132  {
133  debug::trace::quiet = false;
134 
135  image2d<bool> pic;
136  io::pbm::load(pic, MLN_IMG_DIR "/small.pbm");
137 
138  // morpho::impl::general_on_set_centered_fastest(ero, pic, win::rectangle2d(3,3));
139  morpho::general(ero, pic, win::rectangle2d(3,3));
140  morpho::general(dil, pic, win::rectangle2d(3,3));
141 
142  debug::trace::quiet = true;
143  }
144 
145  */
146 
147 
148  {
149  image2d<bool> pic, out, ref;
150  io::pbm::load(pic, MLN_IMG_DIR "/small.pbm");
151 
152  // Rectangle (erosion).
153 
154  ref = morpho::impl::generic::general_on_set(ero, pic, rec);
155 
156  out = morpho::impl::general_on_set_centered(ero, pic, rec);
157  mln_assertion(out == ref);
158 
159  out = morpho::impl::general_on_set_centered_fastest(ero, pic, rec);
160  mln_assertion(out == ref);
161 
162  out = morpho::impl::general_rectangle2d(ero, pic, rec);
163  mln_assertion(out == ref);
164 
165  out = morpho::impl::general_arbitrary_2d(ero, pic, rec);
166  mln_assertion(out == ref);
167 
168  out = morpho::impl::general_directional(ero, pic, rec, 0);
169  mln_assertion(out == ref);
170 
171  out = morpho::impl::general_directional(ero, pic, rec, 1);
172  mln_assertion(out == ref);
173 
174 
175  // Rectangle (dilation).
176 
177  ref = morpho::impl::generic::general_on_set(dil, pic, rec);
178 
179  out = morpho::impl::general_on_set_centered(dil, pic, rec);
180  mln_assertion(out == ref);
181 
182  out = morpho::impl::general_on_set_centered_fastest(dil, pic, rec);
183  mln_assertion(out == ref);
184 
185  out = morpho::impl::general_rectangle2d(dil, pic, rec);
186  mln_assertion(out == ref);
187 
188  out = morpho::impl::general_arbitrary_2d(dil, pic, rec);
189  mln_assertion(out == ref);
190 
191  out = morpho::impl::general_directional(dil, pic, rec, 0);
192  mln_assertion(out == ref);
193 
194  out = morpho::impl::general_directional(dil, pic, rec, 1);
195  mln_assertion(out == ref);
196  }
197 
198 }