27 #ifndef MLN_WORLD_BINARY_2D_SUBSAMPLE_HH
28 # define MLN_WORLD_BINARY_2D_SUBSAMPLE_HH
38 # include <mln/core/image/image2d.hh>
39 # include <mln/core/alias/dpoint2d.hh>
40 # include <mln/data/convert.hh>
41 # include <mln/value/int_u8.hh>
59 image2d<value::int_u8>
60 subsample(
const image2d<bool>& input,
unsigned n);
63 # ifndef MLN_INCLUDE_ONLY
66 image2d<value::int_u8>
67 subsample(
const image2d<bool>& input,
unsigned n)
69 mln_trace(
"world::binary_2d::subsample");
71 mln_precondition(input.is_valid());
78 const bool** ptr =
new const bool*[n];
79 const unsigned nrows = input.nrows() / n;
80 const unsigned ncols = input.ncols() / n;
81 image2d<int_u8> output(nrows, ncols);
83 const unsigned delta_row = input.delta_offset(
down);
85 for (
unsigned row = 0; row <
nrows; ++row)
87 ptr[0] = & input(
point2d(n * row, 0));
88 for (
unsigned i = 1; i < n; ++i)
89 ptr[i] = ptr[i - 1] + delta_row;
90 for (
unsigned col = 0; col <
ncols; ++col)
93 for (
unsigned i = 0; i < n; ++i)
94 for (
unsigned j = 0; j < n; ++j, ++(ptr[i]))
97 output(
point2d(row, col)) = count * mln_max(int_u8) / n / n;
106 # endif // ! MLN_INCLUDE_ONLY
114 #endif // ! MLN_WORLD_BINARY_2D_SUBSAMPLE_HH