27 #ifndef MLN_WORLD_BINARY_2D_ENLARGE_HH
28 # define MLN_WORLD_BINARY_2D_ENLARGE_HH
39 # include <mln/core/image/image2d.hh>
40 # include <mln/core/routine/initialize.hh>
42 # include <mln/value/int_u8.hh>
43 # include <mln/fun/p2v/ternary.hh>
44 # include <mln/fun/v2b/threshold_ge.hh>
46 # include <mln/data/transform.hh>
48 # include <mln/pw/image.hh>
49 # include <mln/pw/cst.hh>
50 # include <mln/pw/value.hh>
51 # include <mln/opt/at.hh>
53 # include <mln/geom/min_row.hh>
54 # include <mln/geom/min_col.hh>
56 # include <mln/core/routine/duplicate.hh>
58 #include <mln/debug/println.hh>
81 # ifndef MLN_INCLUDE_ONLY
98 do_threshold(
float value)
100 return static_cast<int>(255.f *
value);
127 mrow + 2 * input.
nrows() - 1,
128 mcol + 2 * input.
ncols() - 1));
132 opt::at(output, mrow, mcol) = internal::do_threshold(
opt::at(input, mrow, mcol));
134 for (
unsigned col = 2; col < output.
ncols(); col += 2)
136 value = internal::val(
opt::at(input, mrow, mcol + col / 2));
137 value += internal::val(
opt::at(input, mrow, mcol + col / 2 - 1));
138 opt::at(output, mrow, mcol + col) = internal::do_threshold(value / 2);
141 for (
unsigned col = 1; col < output.
ncols(); col += 2)
142 opt::at(output, mrow, mcol + col)
143 = internal::do_threshold(
opt::at(input, mrow, mcol + col / 2));
147 for (
unsigned row = 2; row < output.
nrows(); row += 2)
149 value = internal::val(
opt::at(input, mrow + row / 2, mcol));
150 value += internal::val(
opt::at(input, mrow + row / 2 - 1, mcol));
151 opt::at(output, mrow + row, mcol) = internal::do_threshold(value / 2);
154 for (
unsigned row = 1; row < output.
nrows(); row += 2)
155 opt::at(output, mrow + row, mcol)
156 = internal::do_threshold(
opt::at(input, mrow + row / 2, mcol));
160 for (
unsigned row = 2; row < output.
nrows(); row += 2)
162 for (
unsigned col = 2; col < output.
ncols(); col += 2)
164 value = internal::val(
opt::at(input, mrow + row / 2, mcol + col / 2));
165 value += internal::val(
opt::at(input, mrow + row / 2 - 1, mcol + col / 2));
166 value += internal::val(
opt::at(input, mrow + row / 2, mcol + col / 2 - 1));
167 value += internal::val(
opt::at(input, mrow + row / 2 - 1, mcol + col / 2 - 1));
168 opt::at(output, mrow + row, mcol + col)
169 = internal::do_threshold(value / 4);
171 for (
unsigned col = 1; col < output.
ncols(); col += 2)
173 value = internal::val(
opt::at(input, mrow + row / 2, mcol + col / 2));
174 value += internal::val(
opt::at(input, mrow + row / 2 - 1, mcol + col / 2));
175 opt::at(output, mrow + row, mcol + col) = internal::do_threshold(value / 2);
179 for (
unsigned row = 1; row < output.
nrows(); row += 2)
181 for (
unsigned col = 2; col < output.
ncols(); col += 2)
183 value = internal::val(
opt::at(input, mrow + row / 2, mcol + col / 2));
184 value += internal::val(
opt::at(input, mrow + row / 2, mcol + col / 2 - 1));
185 opt::at(output, mrow + row, mcol + col) = internal::do_threshold(value / 2);
187 for (
unsigned col = 1; col < output.
ncols(); col += 2)
188 opt::at(output, mrow + row, mcol + col)
189 = internal::do_threshold(
opt::at(input, mrow + row / 2, mcol + col / 2));
208 mrow + 2 * input.
nrows() - 1,
209 mcol + 2 * input.
ncols() - 1));
215 for (
unsigned col = 2; col < output.
ncols(); col += 2)
217 value = (
opt::at(input, mrow, mcol + col / 2));
218 value += (
opt::at(input, mrow, mcol + col / 2 - 1));
219 opt::at(output, mrow, mcol + col) = (value / 2);
222 for (
unsigned col = 1; col < output.
ncols(); col += 2)
223 opt::at(output, mrow, mcol + col) = (
opt::at(input, mrow, mcol + col / 2));
227 for (
unsigned row = 2; row < output.
nrows(); row += 2)
229 value = (
opt::at(input, mrow + row / 2, mcol));
230 value += (
opt::at(input, mrow + row / 2 - 1, mcol));
231 opt::at(output, mrow + row, mcol) = (value / 2);
234 for (
unsigned row = 1; row < output.
nrows(); row += 2)
235 opt::at(output, mrow + row, mcol) = (
opt::at(input, mrow + row / 2, mcol));
239 for (
unsigned row = 2; row < output.
nrows(); row += 2)
241 for (
unsigned col = 2; col < output.
ncols(); col += 2)
243 value = (
opt::at(input, mrow + row / 2, mcol + col / 2));
244 value += (
opt::at(input, mrow + row / 2 - 1, mcol + col / 2));
245 value += (
opt::at(input, mrow + row / 2, mcol + col / 2 - 1));
246 value += (
opt::at(input, mrow + row / 2 - 1, mcol + col / 2 - 1));
249 for (
unsigned col = 1; col < output.
ncols(); col += 2)
251 value = (
opt::at(input, mrow + row / 2, mcol + col / 2));
252 value += (
opt::at(input, mrow + row / 2 - 1, mcol + col / 2));
253 opt::at(output, mrow + row, mcol + col) = (value / 2);
257 for (
unsigned row = 1; row < output.
nrows(); row += 2)
259 for (
unsigned col = 2; col < output.
ncols(); col += 2)
261 value = (
opt::at(input, mrow + row / 2, mcol + col / 2));
262 value += (
opt::at(input, mrow + row / 2, mcol + col / 2 - 1));
263 opt::at(output, mrow + row, mcol + col) = (value / 2);
265 for (
unsigned col = 1; col < output.
ncols(); col += 2)
266 opt::at(output, mrow + row, mcol + col)
267 = (
opt::at(input, mrow + row / 2, mcol + col / 2));
274 template <
typename I>
277 do_enlarge_gl(
const I& input,
unsigned n)
281 mln_ch_value(I,
int_u8) output = enlargex2(input);
284 output = enlargex2(output);
290 template <
typename I>
293 do_enlarge_bool(
const I& input,
unsigned n)
316 enlarge_dispatch(
const I& input,
const bool&,
unsigned n)
318 return impl::do_enlarge_bool(input, n);
324 enlarge_dispatch(
const I& input,
const value::int_u8&,
unsigned n)
326 return impl::do_enlarge_gl(input, n);
332 enlarge_dispatch(
const I& input,
const mln_value(I)&,
unsigned n)
337 mlc_abort(I)::check();
338 return mln_concrete(I)();
344 enlarge_dispatch(
const Image<I>& input,
unsigned n)
346 return enlarge_dispatch(
exact(input), mln_value(I)(), n);
355 template <
typename I>
360 mln_trace(
"mln::world::binary_2d::enlarge");
362 mln_precondition(
exact(input).is_valid());
363 typedef mln_site(I) S;
364 mlc_bool(S::dim == 2)::check();
366 mln_concrete(I) output;
370 output = internal::enlarge_dispatch(input, n);
376 # endif // ! MLN_INCLUDE_ONLY
384 #endif // ! MLN_WORLD_BINARY_2D_ENLARGE_HH