$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fill_with_image.cc
1 // Copyright (C) 2007, 2008, 2009, 2013 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/data/fill_with_value.hh>
28 #include <mln/data/fill_with_image.hh>
29 #include <mln/data/compare.hh>
30 
31 #include <mln/core/image/image1d.hh>
32 #include <mln/core/image/image2d.hh>
33 #include <mln/core/image/image3d.hh>
34 #include <mln/pw/image.hh>
35 #include <mln/core/image/flat_image.hh>
36 #include <mln/core/image/vmorph/cast_image.hh>
37 #include <mln/core/image/dmorph/image_if.hh>
38 #include <mln/core/image/dmorph/sub_image.hh>
39 #include <mln/core/image/dmorph/extension_val.hh>
40 
41 #include <mln/fun/p2b/chess.hh>
42 #include <mln/fun/p2v/iota.hh>
43 
44 #include <mln/debug/iota.hh>
45 #include <mln/debug/println.hh>
46 
47 
48 int main()
49 {
50  using namespace mln;
51  const unsigned size = 100;
52 
53  // tests in two dimension
54  {
55  box2d b(point2d(1,2), point2d(2,4));
56  image2d<int> ima(b, 2);
57  debug::iota(ima);
58 
59  box2d b2(point2d(-1,-2), point2d(3,6));
60  image2d<int> ima2(b2, 0);
61  debug::iota(ima2);
62 
63  data::fill_with_image(ima, ima2); // Not so fast version...
64  mln_assertion(ima == (ima2 | b));
65  }
66 
67 
68  // 2d tests
69  {
70  image2d<unsigned int> ima(size, size);
71  image2d<unsigned int> ima2(size, size);
72  debug::iota(ima2);
73 
74  data::fill_with_image(ima, ima2);
75  mln_assertion(ima == ima2);
76  }
77 
78  {
79  box2d b(point2d(1,2), point2d(2,4));
80  image2d<int> ima(b, 2);
81 
82  box2d b2(point2d(-1,-2), point2d(3,6));
83  image2d<int> ima2(b2, 0);
84  debug::iota(ima2);
85 
86  data::fill_with_image(ima, ima2);
87  mln_assertion(ima == (ima2 | b));
88  }
89 
90  {
91  typedef image2d<unsigned char> I;
93 
94  I ima(size, size);
95  I ima2(size, size);
96  data::fill_with_value(ima, 51);
97  data::fill_with_value(ima2, 42);
98 
99  II ima_if = ima | fun::p2b::chess();
100  data::fill_with_image(ima_if, ima2);
101 
102  II::piter p(ima_if.domain());
103  for_all(p)
104  mln_assertion(ima_if(p) == 42);
105 
106  }
107 
108  // tests in three dimension
109  {
110  box3d b(point3d(1,2,1), point3d(2,4,3));
111  image3d<int> ima(b, 2);
112  debug::iota(ima);
113 
114  box3d b2(point3d(-1,-2,-1), point3d(3,6,3));
115  image3d<int> ima2(b2, 2);
116  debug::iota(ima2);
117 
118  image3d<int> ima3(b, 2);
119 
120  data::fill_with_image(ima, ima2); // Not so fast version...
121  mln_assertion(ima == (ima2 | b));
122 
123  data::fill_with_image(ima3, ima); // Fast version...
124  mln_assertion(ima == ima3);
125  }
126 
127  // image 1d test
128  {
129  image1d<unsigned short> ima(size);
130  image1d<unsigned short> out(size);
131 
132  debug::iota(ima);
133  data::fill_with_image(out, ima);
134 
135  mln_assertion(ima == out);
136  }
137 
138 
139  // pw image test
140  {
141  fun::p2v::iota f;
142  const pw::image<fun::p2v::iota, mln::box2d> ima(f, make::box2d(-2,-2, 15,15));
143  image2d<short unsigned int> out(8, 8);
144 
145  data::fill(out, (short unsigned int)0);
146  data::fill_with_image(out, ima);
147  }
148 
149  // flat image test
150  {
151  flat_image<short, box2d> ima(5, mln::make::box2d(size, size));
152  image2d<unsigned short> out(size, size);
153 
154  data::fill_with_value(ima, 51);
155  data::fill_with_image(out, ima);
156 
157  mln_assertion(ima == out);
158  }
159 
160  // image if test
161  {
162  typedef image2d<unsigned short> I;
163  typedef image_if<I, fun::p2b::chess> II;
164 
165  I ima(size, size);
166  I out(size, size);
167  II ima_if = ima | fun::p2b::chess();
168 
169  data::fill_with_value(ima, 42);
170  data::fill_with_value(out, 0);
171  data::fill_with_image(ima_if, ima);
172 
173  mln_piter_(II) p(ima_if.domain());
174  for_all(p)
175  mln_assertion(ima_if(p) == ima(p));
176  }
177 
178  // cast image test
179  {
180  typedef image2d<unsigned short> I;
181  typedef cast_image_<int, I> II;
182 
183  I in(size, size);
184  II cast(in);
185  I out(size, size);
186 
187  data::fill(in, (unsigned short)51);
188  data::fill(out, (unsigned short)42);
189 
190  data::fill_with_image(out, cast);
191 
192  mln_assertion(cast == out);
193  }
194 
195  // sub_image test
196  {
197  typedef image2d<int> I;
198  typedef sub_image< image2d<int>, box2d > II;
199 
200  I ima(size, size);
201  I out(size, size);
202  II sub_ima(ima, make::box2d(4,4, 10,10));
203 
204 
205  data::fill(ima, 51);
206  data::fill(out, 0);
207  data::fill_with_image(sub_ima, ima);
208 
209  II::piter p(sub_ima.domain());
210  for_all(p)
211  mln_assertion(sub_ima(p) == ima(p));
212  }
213 
214  // extended image test
215  {
216  typedef image2d<int> I;
217  typedef extension_val< image2d<int> > II;
218  typedef image2d<unsigned short> III;
219 
220  I ima(size, size);
221  II extend_ima(ima, 5);
222  III out(size, size);
223 
224  data::fill(ima, 51);
225  data::fill_with_image(out, extend_ima);
226 
227  mln_assertion(out == extend_ima);
228  }
229 
230 }