27 #ifndef SCRIBO_CORE_INIT_INTEGRAL_IMAGE_HH
28 # define SCRIBO_CORE_INIT_INTEGRAL_IMAGE_HH
34 # include <mln/core/image/image2d.hh>
41 template <
typename I,
typename F>
43 init_integral_image(const
Image<I>& input_, F& func);
46 # ifndef MLN_INCLUDE_ONLY
52 double square_(
const double& val)
54 double v =
static_cast<double>(val);
59 double identity_(
const double& val)
61 return static_cast<double>(val);
69 template <
typename I,
typename F>
71 init_integral_image(const
Image<I>& input_, F& func)
73 mln_trace(
"scribo::init_integral_image");
75 const I& input =
exact(input_);
76 mln_precondition(input.is_valid());
77 mln_precondition(input.domain().pmin() == literal::origin);
80 initialize(output, input);
83 nrows_ = input.
nrows(),
84 ncols_ = input.
ncols();
86 output.at_(0,0) = func(input.at_(0, 0));
88 for (
unsigned row = 1; row < nrows_; ++row)
89 output.at_(row,0) = output.at_(row - 1, 0) + func(input.at_(row, 0));
91 for (
unsigned col = 1; col < ncols_; ++col)
92 output.at_(0,col) = output.at_(0, col - 1)
93 + func(input.at_(0, col));
95 for (
unsigned row = 1; row < nrows_; ++row)
96 for (
unsigned col = 1; col < ncols_; ++col)
97 output.at_(row, col) = output.at_(row - 1, col)
98 + output.at_(row, col - 1)
99 - output.at_(row - 1, col - 1)
100 + func(input.at_(row, col));
105 #endif // ! MLN_INCLUDE_ONLY
109 #endif // ! SCRIBO_CORE_INIT_INTEGRAL_IMAGE_HH