27 #ifndef MLN_WORLD_BINARY_2D_SUBSAMPLE_HH
28 # define MLN_WORLD_BINARY_2D_SUBSAMPLE_HH
37 # include <mln/core/image/image2d.hh>
38 # include <mln/core/alias/dpoint2d.hh>
39 # include <mln/data/convert.hh>
40 # include <mln/value/int_u8.hh>
58 image2d<value::int_u8>
59 subsample(image2d<bool>& input,
unsigned n);
62 # ifndef MLN_INCLUDE_ONLY
65 image2d<value::int_u8>
66 subsample(image2d<bool>& input,
unsigned n)
68 trace::entering(
"world::binary_2d::subsample");
70 mln_precondition(input.is_valid());
76 image2d<value::int_u8>
79 trace::exiting(
"world::binary_2d::subsample");
83 const bool** ptr =
new const bool*[n];
84 const unsigned nrows = input.nrows() / n;
85 const unsigned ncols = input.ncols() / n;
86 algebra::vec<2, unsigned int> vmin;
87 algebra::vec<2, unsigned int> vmax;
94 image2d<int_u8> output(box<point2d>(pmin, pmax));
97 const unsigned delta_row = input.delta_index(dp_row);
100 for (
unsigned row = 0; row < nrows; ++row)
102 ptr[0] = & input(
point2d(n * row, 0));
103 for (
unsigned i = 1; i < n; ++i)
104 ptr[i] = ptr[i - 1] + delta_row;
105 for (
unsigned col = 0; col < ncols; ++col)
108 for (
unsigned i = 0; i < n; ++i)
110 for (
unsigned j = 0; j < n; ++j, ++(ptr[i]))
116 output(
point2d(row, col)) = count * 255 / n / n;
120 trace::exiting(
"world::binary_2d::subsample");
124 # endif // ! MLN_INCLUDE_ONLY
132 #endif // ! MLN_WORLD_BINARY_2D_SUBSAMPLE_HH