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.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>
77 enlarge(const Image<I>& input,
unsigned n);
80 # ifndef MLN_INCLUDE_ONLY
97 do_threshold(
float value)
99 return static_cast<int>(255.f * value);
114 image2d<value::int_u8>
115 enlargex2(
const image2d<bool>& input)
119 mln_precondition(input.is_valid());
126 mrow + 2 * input.nrows() - 1,
127 mcol + 2 * input.ncols() - 1));
131 opt::at(output, mrow, mcol) = internal::do_threshold(
opt::at(input, mrow, mcol));
133 for (
unsigned col = 2; col < output.ncols(); col += 2)
135 value = internal::val(
opt::at(input, mrow, mcol + col / 2));
136 value += internal::val(
opt::at(input, mrow, mcol + col / 2 - 1));
137 opt::at(output, mrow, mcol + col) = internal::do_threshold(value / 2);
140 for (
unsigned col = 1; col < output.ncols(); col += 2)
141 opt::at(output, mrow, mcol + col)
142 = internal::do_threshold(
opt::at(input, mrow, mcol + col / 2));
146 for (
unsigned row = 2; row < output.nrows(); row += 2)
148 value = internal::val(
opt::at(input, mrow + row / 2, mcol));
149 value += internal::val(
opt::at(input, mrow + row / 2 - 1, mcol));
150 opt::at(output, mrow + row, mcol) = internal::do_threshold(value / 2);
153 for (
unsigned row = 1; row < output.nrows(); row += 2)
154 opt::at(output, mrow + row, mcol)
155 = internal::do_threshold(
opt::at(input, mrow + row / 2, mcol));
159 for (
unsigned row = 2; row < output.nrows(); row += 2)
161 for (
unsigned col = 2; col < output.ncols(); col += 2)
163 value = internal::val(
opt::at(input, mrow + row / 2, mcol + col / 2));
164 value += internal::val(
opt::at(input, mrow + row / 2 - 1, mcol + col / 2));
165 value += internal::val(
opt::at(input, mrow + row / 2, mcol + col / 2 - 1));
166 value += internal::val(
opt::at(input, mrow + row / 2 - 1, mcol + col / 2 - 1));
167 opt::at(output, mrow + row, mcol + col)
168 = internal::do_threshold(value / 4);
170 for (
unsigned col = 1; col < output.ncols(); col += 2)
172 value = internal::val(
opt::at(input, mrow + row / 2, mcol + col / 2));
173 value += internal::val(
opt::at(input, mrow + row / 2 - 1, mcol + col / 2));
174 opt::at(output, mrow + row, mcol + col) = internal::do_threshold(value / 2);
178 for (
unsigned row = 1; row < output.nrows(); row += 2)
180 for (
unsigned col = 2; col < output.ncols(); col += 2)
182 value = internal::val(
opt::at(input, mrow + row / 2, mcol + col / 2));
183 value += internal::val(
opt::at(input, mrow + row / 2, mcol + col / 2 - 1));
184 opt::at(output, mrow + row, mcol + col) = internal::do_threshold(value / 2);
186 for (
unsigned col = 1; col < output.ncols(); col += 2)
187 opt::at(output, mrow + row, mcol + col)
188 = internal::do_threshold(
opt::at(input, mrow + row / 2, mcol + col / 2));
197 image2d<value::int_u8>
198 enlargex2(
const image2d<value::int_u8>& input)
207 mrow + 2 * input.nrows() - 1,
208 mcol + 2 * input.ncols() - 1));
214 for (
unsigned col = 2; col < output.ncols(); col += 2)
216 value = (
opt::at(input, mrow, mcol + col / 2));
217 value += (
opt::at(input, mrow, mcol + col / 2 - 1));
218 opt::at(output, mrow, mcol + col) = (value / 2);
221 for (
unsigned col = 1; col < output.ncols(); col += 2)
222 opt::at(output, mrow, mcol + col) = (
opt::at(input, mrow, mcol + col / 2));
226 for (
unsigned row = 2; row < output.nrows(); row += 2)
228 value = (
opt::at(input, mrow + row / 2, mcol));
229 value += (
opt::at(input, mrow + row / 2 - 1, mcol));
230 opt::at(output, mrow + row, mcol) = (value / 2);
233 for (
unsigned row = 1; row < output.nrows(); row += 2)
234 opt::at(output, mrow + row, mcol) = (
opt::at(input, mrow + row / 2, mcol));
238 for (
unsigned row = 2; row < output.nrows(); row += 2)
240 for (
unsigned col = 2; col < output.ncols(); col += 2)
242 value = (
opt::at(input, mrow + row / 2, mcol + col / 2));
243 value += (
opt::at(input, mrow + row / 2 - 1, mcol + col / 2));
244 value += (
opt::at(input, mrow + row / 2, mcol + col / 2 - 1));
245 value += (
opt::at(input, mrow + row / 2 - 1, mcol + col / 2 - 1));
246 opt::at(output, mrow + row, mcol + col) = ((unsigned(value)+2) / 4);
248 for (
unsigned col = 1; col < output.ncols(); col += 2)
250 value = (
opt::at(input, mrow + row / 2, mcol + col / 2));
251 value += (
opt::at(input, mrow + row / 2 - 1, mcol + col / 2));
252 opt::at(output, mrow + row, mcol + col) = (value / 2);
256 for (
unsigned row = 1; row < output.nrows(); row += 2)
258 for (
unsigned col = 2; col < output.ncols(); col += 2)
260 value = (
opt::at(input, mrow + row / 2, mcol + col / 2));
261 value += (
opt::at(input, mrow + row / 2, mcol + col / 2 - 1));
262 opt::at(output, mrow + row, mcol + col) = (value / 2);
264 for (
unsigned col = 1; col < output.ncols(); col += 2)
265 opt::at(output, mrow + row, mcol + col)
266 = (
opt::at(input, mrow + row / 2, mcol + col / 2));
273 template <
typename I>
276 do_enlarge_gl(const I& input,
unsigned n)
280 mln_ch_value(I,int_u8) output = enlargex2(input);
283 output = enlargex2(output);
289 template <typename I>
292 do_enlarge_bool(const I& input,
unsigned n)
296 =
data::transform(tmp, fun::v2b::threshold<value::int_u8>(150));
314 enlarge_dispatch(const I& input, const
bool&,
unsigned n)
316 return impl::do_enlarge_bool(input, n);
322 enlarge_dispatch(const I& input, const value::int_u8&,
unsigned n)
324 return impl::do_enlarge_gl(input, n);
330 enlarge_dispatch(const I& input, const mln_value(I)&,
unsigned n)
335 mlc_abort(I)::check();
336 return mln_concrete(I)();
342 enlarge_dispatch(const Image<I>& input,
unsigned n)
344 return enlarge_dispatch(exact(input), mln_value(I)(), n);
353 template <
typename I>
356 enlarge(const Image<I>& input,
unsigned n)
358 trace::entering(
"mln::world::binary_2d::enlarge");
360 mln_precondition(exact(input).is_valid());
361 typedef mln_site(I) S;
362 mlc_bool(S::dim == 2)::check();
364 mln_concrete(I) output;
368 output = internal::enlarge_dispatch(input, n);
370 trace::exiting("mln::world::binary_2d::enlarge");
375 # endif // ! MLN_INCLUDE_ONLY
383 #endif // ! MLN_WORLD_BINARY_2D_ENLARGE_HH