28 #ifndef SCRIBO_CANVAS_INTEGRAL_BROWSING_HH
29 # define SCRIBO_CANVAS_INTEGRAL_BROWSING_HH
31 # include <mln/core/image/image2d.hh>
32 # include <mln/util/couple.hh>
45 unsigned w,
unsigned h,
49 # ifndef MLN_INCLUDE_ONLY
57 double sum,
double sum_2,
unsigned n,
59 double& mean,
double& stddev)
64 double num = (sum_2 - sum * sum / n);
80 unsigned w,
unsigned h,
86 Ptr a_ima, b_ima, c_ima, d_ima;
92 if (w > (ima.domain().ncols() - ima.border()))
94 w =
std::min(ima.domain().ncols(), ima.domain().nrows()) - ima.border();
97 mln_trace_warning(
"integral_browsing - "
98 "Adjusting window width since it"
99 " was larger than image height.");
101 if (h > (ima.domain().nrows() - ima.border()))
103 h =
std::min(ima.domain().ncols(), ima.domain().nrows()) - ima.border();
106 mln_trace_warning(
"integral_browsing - "
107 "Adjusting window height since it"
108 " was larger than image width.");
121 offset_down = ima.delta_offset(
dpoint2d(step, 0)),
122 offset_ante = ima.delta_offset(
dpoint2d(0, -w)),
123 offset_below = ima.delta_offset(
dpoint2d(+h, 0));
127 max_row_mid = nrows - 1 - h/2,
129 max_col_mid =
ncols - 1 - w/2,
131 step_2 = step * step,
133 h_top = row_0 + h/2 + 1,
134 w_left = col_0 + w/2 + 1;
139 for (col = col_0; col <= max_col_mid; col += step) ;
140 int w_right =
ncols - col + w/2;
149 d_tl_start, d_tr_start,
150 b_ml_start = 0, d_ml_start = 0, b_mr_start = 0, d_mr_start = 0,
151 b_bl_start = 0, d_bl_start = 0, b_br_start = 0, d_br = 0;
155 unsigned s_2 = s * s;
162 delta_start_left = step * w_left,
163 delta_start_right = step * w_right,
166 size_tl_start = h_top * w_left,
168 delta_size_tl = h_top * step,
170 delta_size_tr = h_top * step,
171 size_tr_start = h_top * w_right,
174 d_tl_start = & ima.at_(row_0 + h/2, col_0 + w/2);
175 d_tr_start = & ima.at_(row_0 + h/2,
ncols - 1);
177 for (row = row_0; row <= max_row_top; row += step)
183 size_tl = size_tl_start;
185 for (col = col_0; col <= max_col_left; col += step)
188 internal::compute_stats(d_ima->first(),
192 functor.exec(mean, stddev);
194 size_tl += delta_size_tl;
197 delta_size_tl += step_2;
198 size_tl_start += delta_start_left;
199 d_tl_start += offset_down;
203 c_ima = d_ima + offset_ante;
205 for (; col <= max_col_mid; col += step)
208 internal::compute_stats(d_ima->first() - c_ima->first(),
209 d_ima->second() - c_ima->second(),
212 functor.exec(mean, stddev);
223 d_sum = d_ima->first(),
224 d_sum_2 = d_ima->second();
225 size_tr = size_tr_start;
227 for (; col <
ncols; col += step)
230 internal::compute_stats(d_sum - c_ima->first(),
231 d_sum_2 - c_ima->second(),
234 functor.exec(mean, stddev);
236 size_tr -= delta_size_tr;
239 delta_size_tr += step_2;
240 size_tr_start += delta_start_right;
241 d_tr_start += offset_down;
242 functor.end_of_row(row);
252 size_ml_start = h * w_left,
257 size_mr_start = h * w_right,
260 if (row <= max_row_mid)
262 b_ml_start = & ima.at_(row - h/2 - 1, col_0 + w/2);
263 d_ml_start = b_ml_start + offset_below;
264 b_mr_start = & ima.at_(row - h/2 - 1, ncols - 1);
265 d_mr_start = b_mr_start + offset_below;
268 for (; row <= max_row_mid; row += step)
273 size_ml = size_ml_start;
277 for (col = col_0; col <= max_col_left; col += step)
280 internal::compute_stats(d_ima->first() - b_ima->first(),
281 d_ima->second() - b_ima->second(),
284 functor.exec(mean, stddev);
290 b_ml_start += offset_down;
291 d_ml_start += offset_down;
295 a_ima = b_ima + offset_ante;
296 c_ima = d_ima + offset_ante;
298 for (; col <= max_col_mid; col += step)
302 internal::compute_stats((d_ima->first() - b_ima->first()) + (a_ima->first() - c_ima->first()),
303 (d_ima->second() - b_ima->second()) + (a_ima->second() - c_ima->second()),
307 functor.exec(mean, stddev);
317 size_mr = size_mr_start;
321 d_b_sum = d_ima->first() - b_ima->first(),
322 d_b_sum_2 = d_ima->second() - b_ima->second();
324 for (; col <
ncols; col += step)
327 internal::compute_stats(d_b_sum + (a_ima->first() - c_ima->first()),
328 d_b_sum_2 + (a_ima->second() - c_ima->second()),
331 functor.exec(mean, stddev);
337 b_mr_start += offset_down;
338 d_mr_start += offset_down;
339 functor.end_of_row(row);
348 size_bl_start = (nrows - row + h/2) * w_left,
350 delta_size_bl = (nrows - row + h/2) * step,
351 size_bc = (nrows - row + h/2) * w,
353 size_br_start = (nrows - row + h/2) * w_right,
354 delta_size_br = (nrows - row + h/2) * step,
359 b_bl_start = & ima.at_(row - h/2 - 1, col_0 + w/2);
360 d_bl_start = & ima.at_(nrows - 1, col_0 + w/2);
361 b_br_start = & ima.at_(row - h/2 - 1, ncols - 1);
362 d_br = & ima.at_(nrows - 1, ncols - 1);
365 for (; row <
nrows; row += step)
370 size_bl = size_bl_start;
374 for (col = col_0; col <= max_col_left; col += step)
377 internal::compute_stats(d_ima->first() - b_ima->first(),
378 d_ima->second() - b_ima->second(),
381 functor.exec(mean, stddev);
384 size_bl += delta_size_bl;
387 delta_size_bl -= step_2;
388 size_bl_start -= delta_start_left;
389 b_bl_start += offset_down;
393 a_ima = b_ima + offset_ante;
394 c_ima = d_ima + offset_ante;
396 for (; col <= max_col_mid; col += step)
399 internal::compute_stats((d_ima->first() - b_ima->first()) + (a_ima->first() - c_ima->first()),
400 (d_ima->second() - b_ima->second()) + (a_ima->second() - c_ima->second()),
403 functor.exec(mean, stddev);
414 size_br = size_br_start;
418 d_b_sum = d_ima->first() - b_ima->first(),
419 d_b_sum_2 = d_ima->second() - b_ima->second();
421 for (; col <
ncols; col += step)
424 internal::compute_stats(d_b_sum + (a_ima->first() - c_ima->first()),
425 d_b_sum_2 + (a_ima->second() - c_ima->second()),
428 functor.exec(mean, stddev);
431 size_br -= delta_size_br;
434 delta_size_br -= step_2;
435 size_br_start -= delta_start_right;
436 b_br_start += offset_down;
437 functor.end_of_row(row);
443 # endif // ! MLN_INCLUDE_ONLY
451 #endif // ! SCRIBO_CANVAS_INTEGRAL_BROWSING_HH