203 current_row [0].setZero ();
204 so_current_row [0].setZero ();
205 count_current_row [0] = 0;
206 for (
unsigned colIdx = 0, valIdx = 0; colIdx < width_; ++colIdx, valIdx += element_stride)
208 current_row [colIdx + 1] = previous_row [colIdx + 1] + current_row [colIdx] - previous_row [colIdx];
209 so_current_row [colIdx + 1] = so_previous_row [colIdx + 1] + so_current_row [colIdx] - so_previous_row [colIdx];
210 count_current_row [colIdx + 1] = count_previous_row [colIdx + 1] + count_current_row [colIdx] - count_previous_row [colIdx];
212 const auto* element =
reinterpret_cast <const InputType*
> (&data [valIdx]);
213 if (std::isfinite (element->sum ()))
215 current_row [colIdx + 1] += element->template cast<typename IntegralImageTypeTraits<DataType>::IntegralType>();
216 ++(count_current_row [colIdx + 1]);
217 for (
unsigned myIdx = 0, elIdx = 0; myIdx < Dimension; ++myIdx)
218 for (
unsigned mxIdx = myIdx; mxIdx < Dimension; ++mxIdx, ++elIdx)
219 so_current_row [colIdx + 1][elIdx] += (*element)[myIdx] * (*element)[mxIdx];
227template <
typename DataType>
void
230 if ((width + 1) * (height + 1) > first_order_integral_image_.size () )
234 const std::size_t ii_size =
static_cast<std::size_t
>(width_ + 1) *
static_cast<std::size_t
>(height_ + 1);
235 first_order_integral_image_.resize (ii_size);
236 finite_values_integral_image_.resize (ii_size);
237 if (compute_second_order_integral_images_)
238 second_order_integral_image_.resize (ii_size);
240 computeIntegralImages (data, row_stride, element_stride);
246 unsigned start_x,
unsigned start_y,
unsigned width,
unsigned height)
const
248 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
249 const unsigned upper_right_idx = upper_left_idx + width;
250 const unsigned lower_left_idx = (start_y + height) * (width_ + 1) + start_x;
251 const unsigned lower_right_idx = lower_left_idx + width;
253 return (first_order_integral_image_[lower_right_idx] + first_order_integral_image_[upper_left_idx] -
254 first_order_integral_image_[upper_right_idx] - first_order_integral_image_[lower_left_idx] );
260 unsigned start_x,
unsigned start_y,
unsigned width,
unsigned height)
const
262 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
263 const unsigned upper_right_idx = upper_left_idx + width;
264 const unsigned lower_left_idx = (start_y + height) * (width_ + 1) + start_x;
265 const unsigned lower_right_idx = lower_left_idx + width;
267 return (second_order_integral_image_[lower_right_idx] + second_order_integral_image_[upper_left_idx] -
268 second_order_integral_image_[upper_right_idx] - second_order_integral_image_[lower_left_idx] );
272template <
typename DataType>
unsigned
274 unsigned start_x,
unsigned start_y,
unsigned width,
unsigned height)
const
276 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
277 const unsigned upper_right_idx = upper_left_idx + width;
278 const unsigned lower_left_idx = (start_y + height) * (width_ + 1) + start_x;
279 const unsigned lower_right_idx = lower_left_idx + width;
281 return (finite_values_integral_image_[lower_right_idx] + finite_values_integral_image_[upper_left_idx] -
282 finite_values_integral_image_[upper_right_idx] - finite_values_integral_image_[lower_left_idx] );
288 unsigned start_x,
unsigned start_y,
unsigned end_x,
unsigned end_y)
const
290 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
291 const unsigned upper_right_idx = start_y * (width_ + 1) + end_x;
292 const unsigned lower_left_idx = end_y * (width_ + 1) + start_x;
293 const unsigned lower_right_idx = end_y * (width_ + 1) + end_x;
295 return (first_order_integral_image_[lower_right_idx] + first_order_integral_image_[upper_left_idx] -
296 first_order_integral_image_[upper_right_idx] - first_order_integral_image_[lower_left_idx] );
302 unsigned start_x,
unsigned start_y,
unsigned end_x,
unsigned end_y)
const
304 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
305 const unsigned upper_right_idx = start_y * (width_ + 1) + end_x;
306 const unsigned lower_left_idx = end_y * (width_ + 1) + start_x;
307 const unsigned lower_right_idx = end_y * (width_ + 1) + end_x;
309 return (second_order_integral_image_[lower_right_idx] + second_order_integral_image_[upper_left_idx] -
310 second_order_integral_image_[upper_right_idx] - second_order_integral_image_[lower_left_idx] );
314template <
typename DataType>
unsigned
316 unsigned start_x,
unsigned start_y,
unsigned end_x,
unsigned end_y)
const
318 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
319 const unsigned upper_right_idx = start_y * (width_ + 1) + end_x;
320 const unsigned lower_left_idx = end_y * (width_ + 1) + start_x;
321 const unsigned lower_right_idx = end_y * (width_ + 1) + end_x;
323 return (finite_values_integral_image_[lower_right_idx] + finite_values_integral_image_[upper_left_idx] -
324 finite_values_integral_image_[upper_right_idx] - finite_values_integral_image_[lower_left_idx] );
328template <
typename DataType>
void
330 const DataType *data,
unsigned row_stride,
unsigned element_stride)
332 ElementType* previous_row = first_order_integral_image_.data();
333 ElementType* current_row = previous_row + (width_ + 1);
334 std::fill_n(previous_row, width_ + 1, 0);
336 unsigned* count_previous_row = finite_values_integral_image_.data();
337 unsigned* count_current_row = count_previous_row + (width_ + 1);
338 std::fill_n(count_previous_row, width_ + 1, 0);
340 if (!compute_second_order_integral_images_)
342 for (
unsigned rowIdx = 0; rowIdx < height_; ++rowIdx, data += row_stride,
343 previous_row = current_row, current_row += (width_ + 1),
344 count_previous_row = count_current_row, count_current_row += (width_ + 1))
346 current_row [0] = 0.0;
347 count_current_row [0] = 0;
348 for (
unsigned colIdx = 0, valIdx = 0; colIdx < width_; ++colIdx, valIdx += element_stride)
350 current_row [colIdx + 1] = previous_row [colIdx + 1] + current_row [colIdx] - previous_row [colIdx];
351 count_current_row [colIdx + 1] = count_previous_row [colIdx + 1] + count_current_row [colIdx] - count_previous_row [colIdx];
352 if (std::isfinite (data [valIdx]))
354 current_row [colIdx + 1] += data [valIdx];
355 ++(count_current_row [colIdx + 1]);
362 SecondOrderType* so_previous_row = second_order_integral_image_.data();
363 SecondOrderType* so_current_row = so_previous_row + (width_ + 1);
364 std::fill_n(so_previous_row, width_ + 1, 0);
366 for (
unsigned rowIdx = 0; rowIdx < height_; ++rowIdx, data += row_stride,
367 previous_row = current_row, current_row += (width_ + 1),
368 count_previous_row = count_current_row, count_current_row += (width_ + 1),
369 so_previous_row = so_current_row, so_current_row += (width_ + 1))
371 current_row [0] = 0.0;
372 so_current_row [0] = 0.0;
373 count_current_row [0] = 0;
374 for (
unsigned colIdx = 0, valIdx = 0; colIdx < width_; ++colIdx, valIdx += element_stride)
376 current_row [colIdx + 1] = previous_row [colIdx + 1] + current_row [colIdx] - previous_row [colIdx];
377 so_current_row [colIdx + 1] = so_previous_row [colIdx + 1] + so_current_row [colIdx] - so_previous_row [colIdx];
378 count_current_row [colIdx + 1] = count_previous_row [colIdx + 1] + count_current_row [colIdx] - count_previous_row [colIdx];
379 if (std::isfinite (data[valIdx]))
381 current_row [colIdx + 1] += data[valIdx];
382 so_current_row [colIdx + 1] += data[valIdx] * data[valIdx];
383 ++(count_current_row [colIdx + 1]);