41 #ifndef PCL_INTEGRAL_IMAGE2D_IMPL_H_
42 #define PCL_INTEGRAL_IMAGE2D_IMPL_H_
48 template <
typename DataType,
unsigned Dimension>
void
51 compute_second_order_integral_images_ = compute_second_order_integral_images;
55 template <
typename DataType,
unsigned Dimension>
void
58 if ((width + 1) * (height + 1) > first_order_integral_image_.size () )
62 first_order_integral_image_.resize ( (width_ + 1) * (height_ + 1) );
63 finite_values_integral_image_.resize ( (width_ + 1) * (height_ + 1) );
64 if (compute_second_order_integral_images_)
65 second_order_integral_image_.resize ( (width_ + 1) * (height_ + 1) );
67 computeIntegralImages (data, row_stride, element_stride);
73 unsigned start_x,
unsigned start_y,
unsigned width,
unsigned height)
const
75 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
76 const unsigned upper_right_idx = upper_left_idx + width;
77 const unsigned lower_left_idx = (start_y + height) * (width_ + 1) + start_x;
78 const unsigned lower_right_idx = lower_left_idx + width;
80 return (first_order_integral_image_[lower_right_idx] + first_order_integral_image_[upper_left_idx] -
81 first_order_integral_image_[upper_right_idx] - first_order_integral_image_[lower_left_idx] );
87 unsigned start_x,
unsigned start_y,
unsigned width,
unsigned height)
const
89 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
90 const unsigned upper_right_idx = upper_left_idx + width;
91 const unsigned lower_left_idx = (start_y + height) * (width_ + 1) + start_x;
92 const unsigned lower_right_idx = lower_left_idx + width;
94 return (second_order_integral_image_[lower_right_idx] + second_order_integral_image_[upper_left_idx] -
95 second_order_integral_image_[upper_right_idx] - second_order_integral_image_[lower_left_idx] );
99 template <
typename DataType,
unsigned Dimension>
unsigned
101 unsigned start_x,
unsigned start_y,
unsigned width,
unsigned height)
const
103 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
104 const unsigned upper_right_idx = upper_left_idx + width;
105 const unsigned lower_left_idx = (start_y + height) * (width_ + 1) + start_x;
106 const unsigned lower_right_idx = lower_left_idx + width;
108 return (finite_values_integral_image_[lower_right_idx] + finite_values_integral_image_[upper_left_idx] -
109 finite_values_integral_image_[upper_right_idx] - finite_values_integral_image_[lower_left_idx] );
115 unsigned start_x,
unsigned start_y,
unsigned end_x,
unsigned end_y)
const
117 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
118 const unsigned upper_right_idx = start_y * (width_ + 1) + end_x;
119 const unsigned lower_left_idx = end_y * (width_ + 1) + start_x;
120 const unsigned lower_right_idx = end_y * (width_ + 1) + end_x;
122 return (first_order_integral_image_[lower_right_idx] + first_order_integral_image_[upper_left_idx] -
123 first_order_integral_image_[upper_right_idx] - first_order_integral_image_[lower_left_idx] );
129 unsigned start_x,
unsigned start_y,
unsigned end_x,
unsigned end_y)
const
131 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
132 const unsigned upper_right_idx = start_y * (width_ + 1) + end_x;
133 const unsigned lower_left_idx = end_y * (width_ + 1) + start_x;
134 const unsigned lower_right_idx = end_y * (width_ + 1) + end_x;
136 return (second_order_integral_image_[lower_right_idx] + second_order_integral_image_[upper_left_idx] -
137 second_order_integral_image_[upper_right_idx] - second_order_integral_image_[lower_left_idx] );
141 template <
typename DataType,
unsigned Dimension>
unsigned
143 unsigned start_x,
unsigned start_y,
unsigned end_x,
unsigned end_y)
const
145 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
146 const unsigned upper_right_idx = start_y * (width_ + 1) + end_x;
147 const unsigned lower_left_idx = end_y * (width_ + 1) + start_x;
148 const unsigned lower_right_idx = end_y * (width_ + 1) + end_x;
150 return (finite_values_integral_image_[lower_right_idx] + finite_values_integral_image_[upper_left_idx] -
151 finite_values_integral_image_[upper_right_idx] - finite_values_integral_image_[lower_left_idx] );
155 template <
typename DataType,
unsigned Dimension>
void
157 const DataType *data,
unsigned row_stride,
unsigned element_stride)
159 ElementType* previous_row = &first_order_integral_image_[0];
160 ElementType* current_row = previous_row + (width_ + 1);
161 memset (previous_row, 0,
sizeof (ElementType) * (width_ + 1));
163 unsigned* count_previous_row = &finite_values_integral_image_[0];
164 unsigned* count_current_row = count_previous_row + (width_ + 1);
165 memset (count_previous_row, 0,
sizeof (
unsigned) * (width_ + 1));
167 if (!compute_second_order_integral_images_)
169 for (
unsigned rowIdx = 0; rowIdx < height_; ++rowIdx, data += row_stride,
170 previous_row = current_row, current_row += (width_ + 1),
171 count_previous_row = count_current_row, count_current_row += (width_ + 1))
173 current_row [0].setZero ();
174 count_current_row [0] = 0;
175 for (
unsigned colIdx = 0, valIdx = 0; colIdx < width_; ++colIdx, valIdx += element_stride)
177 current_row [colIdx + 1] = previous_row [colIdx + 1] + current_row [colIdx] - previous_row [colIdx];
178 count_current_row [colIdx + 1] = count_previous_row [colIdx + 1] + count_current_row [colIdx] - count_previous_row [colIdx];
179 const InputType* element =
reinterpret_cast <const InputType*
> (&data [valIdx]);
180 if (std::isfinite (element->sum ()))
182 current_row [colIdx + 1] += element->template cast<typename IntegralImageTypeTraits<DataType>::IntegralType>();
183 ++(count_current_row [colIdx + 1]);
190 SecondOrderType* so_previous_row = &second_order_integral_image_[0];
191 SecondOrderType* so_current_row = so_previous_row + (width_ + 1);
192 memset (so_previous_row, 0,
sizeof (SecondOrderType) * (width_ + 1));
194 SecondOrderType so_element;
195 for (
unsigned rowIdx = 0; rowIdx < height_; ++rowIdx, data += row_stride,
196 previous_row = current_row, current_row += (width_ + 1),
197 count_previous_row = count_current_row, count_current_row += (width_ + 1),
198 so_previous_row = so_current_row, so_current_row += (width_ + 1))
200 current_row [0].setZero ();
201 so_current_row [0].setZero ();
202 count_current_row [0] = 0;
203 for (
unsigned colIdx = 0, valIdx = 0; colIdx < width_; ++colIdx, valIdx += element_stride)
205 current_row [colIdx + 1] = previous_row [colIdx + 1] + current_row [colIdx] - previous_row [colIdx];
206 so_current_row [colIdx + 1] = so_previous_row [colIdx + 1] + so_current_row [colIdx] - so_previous_row [colIdx];
207 count_current_row [colIdx + 1] = count_previous_row [colIdx + 1] + count_current_row [colIdx] - count_previous_row [colIdx];
209 const InputType* element =
reinterpret_cast <const InputType*
> (&data [valIdx]);
210 if (std::isfinite (element->sum ()))
212 current_row [colIdx + 1] += element->template cast<typename IntegralImageTypeTraits<DataType>::IntegralType>();
213 ++(count_current_row [colIdx + 1]);
214 for (
unsigned myIdx = 0, elIdx = 0; myIdx < Dimension; ++myIdx)
215 for (
unsigned mxIdx = myIdx; mxIdx < Dimension; ++mxIdx, ++elIdx)
216 so_current_row [colIdx + 1][elIdx] += (*element)[myIdx] * (*element)[mxIdx];
224 template <
typename DataType>
void
227 if ((width + 1) * (height + 1) > first_order_integral_image_.size () )
231 first_order_integral_image_.resize ( (width_ + 1) * (height_ + 1) );
232 finite_values_integral_image_.resize ( (width_ + 1) * (height_ + 1) );
233 if (compute_second_order_integral_images_)
234 second_order_integral_image_.resize ( (width_ + 1) * (height_ + 1) );
236 computeIntegralImages (data, row_stride, element_stride);
242 unsigned start_x,
unsigned start_y,
unsigned width,
unsigned height)
const
244 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
245 const unsigned upper_right_idx = upper_left_idx + width;
246 const unsigned lower_left_idx = (start_y + height) * (width_ + 1) + start_x;
247 const unsigned lower_right_idx = lower_left_idx + width;
249 return (first_order_integral_image_[lower_right_idx] + first_order_integral_image_[upper_left_idx] -
250 first_order_integral_image_[upper_right_idx] - first_order_integral_image_[lower_left_idx] );
256 unsigned start_x,
unsigned start_y,
unsigned width,
unsigned height)
const
258 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
259 const unsigned upper_right_idx = upper_left_idx + width;
260 const unsigned lower_left_idx = (start_y + height) * (width_ + 1) + start_x;
261 const unsigned lower_right_idx = lower_left_idx + width;
263 return (second_order_integral_image_[lower_right_idx] + second_order_integral_image_[upper_left_idx] -
264 second_order_integral_image_[upper_right_idx] - second_order_integral_image_[lower_left_idx] );
268 template <
typename DataType>
unsigned
270 unsigned start_x,
unsigned start_y,
unsigned width,
unsigned height)
const
272 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
273 const unsigned upper_right_idx = upper_left_idx + width;
274 const unsigned lower_left_idx = (start_y + height) * (width_ + 1) + start_x;
275 const unsigned lower_right_idx = lower_left_idx + width;
277 return (finite_values_integral_image_[lower_right_idx] + finite_values_integral_image_[upper_left_idx] -
278 finite_values_integral_image_[upper_right_idx] - finite_values_integral_image_[lower_left_idx] );
284 unsigned start_x,
unsigned start_y,
unsigned end_x,
unsigned end_y)
const
286 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
287 const unsigned upper_right_idx = start_y * (width_ + 1) + end_x;
288 const unsigned lower_left_idx = end_y * (width_ + 1) + start_x;
289 const unsigned lower_right_idx = end_y * (width_ + 1) + end_x;
291 return (first_order_integral_image_[lower_right_idx] + first_order_integral_image_[upper_left_idx] -
292 first_order_integral_image_[upper_right_idx] - first_order_integral_image_[lower_left_idx] );
298 unsigned start_x,
unsigned start_y,
unsigned end_x,
unsigned end_y)
const
300 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
301 const unsigned upper_right_idx = start_y * (width_ + 1) + end_x;
302 const unsigned lower_left_idx = end_y * (width_ + 1) + start_x;
303 const unsigned lower_right_idx = end_y * (width_ + 1) + end_x;
305 return (second_order_integral_image_[lower_right_idx] + second_order_integral_image_[upper_left_idx] -
306 second_order_integral_image_[upper_right_idx] - second_order_integral_image_[lower_left_idx] );
310 template <
typename DataType>
unsigned
312 unsigned start_x,
unsigned start_y,
unsigned end_x,
unsigned end_y)
const
314 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
315 const unsigned upper_right_idx = start_y * (width_ + 1) + end_x;
316 const unsigned lower_left_idx = end_y * (width_ + 1) + start_x;
317 const unsigned lower_right_idx = end_y * (width_ + 1) + end_x;
319 return (finite_values_integral_image_[lower_right_idx] + finite_values_integral_image_[upper_left_idx] -
320 finite_values_integral_image_[upper_right_idx] - finite_values_integral_image_[lower_left_idx] );
324 template <
typename DataType>
void
326 const DataType *data,
unsigned row_stride,
unsigned element_stride)
328 ElementType* previous_row = &first_order_integral_image_[0];
329 ElementType* current_row = previous_row + (width_ + 1);
330 memset (previous_row, 0,
sizeof (
ElementType) * (width_ + 1));
332 unsigned* count_previous_row = &finite_values_integral_image_[0];
333 unsigned* count_current_row = count_previous_row + (width_ + 1);
334 memset (count_previous_row, 0,
sizeof (
unsigned) * (width_ + 1));
336 if (!compute_second_order_integral_images_)
338 for (
unsigned rowIdx = 0; rowIdx < height_; ++rowIdx, data += row_stride,
339 previous_row = current_row, current_row += (width_ + 1),
340 count_previous_row = count_current_row, count_current_row += (width_ + 1))
342 current_row [0] = 0.0;
343 count_current_row [0] = 0;
344 for (
unsigned colIdx = 0, valIdx = 0; colIdx < width_; ++colIdx, valIdx += element_stride)
346 current_row [colIdx + 1] = previous_row [colIdx + 1] + current_row [colIdx] - previous_row [colIdx];
347 count_current_row [colIdx + 1] = count_previous_row [colIdx + 1] + count_current_row [colIdx] - count_previous_row [colIdx];
348 if (std::isfinite (data [valIdx]))
350 current_row [colIdx + 1] += data [valIdx];
351 ++(count_current_row [colIdx + 1]);
362 for (
unsigned rowIdx = 0; rowIdx < height_; ++rowIdx, data += row_stride,
363 previous_row = current_row, current_row += (width_ + 1),
364 count_previous_row = count_current_row, count_current_row += (width_ + 1),
365 so_previous_row = so_current_row, so_current_row += (width_ + 1))
367 current_row [0] = 0.0;
368 so_current_row [0] = 0.0;
369 count_current_row [0] = 0;
370 for (
unsigned colIdx = 0, valIdx = 0; colIdx < width_; ++colIdx, valIdx += element_stride)
372 current_row [colIdx + 1] = previous_row [colIdx + 1] + current_row [colIdx] - previous_row [colIdx];
373 so_current_row [colIdx + 1] = so_previous_row [colIdx + 1] + so_current_row [colIdx] - so_previous_row [colIdx];
374 count_current_row [colIdx + 1] = count_previous_row [colIdx + 1] + count_current_row [colIdx] - count_previous_row [colIdx];
375 if (std::isfinite (data[valIdx]))
377 current_row [colIdx + 1] += data[valIdx];
378 so_current_row [colIdx + 1] += data[valIdx] * data[valIdx];
379 ++(count_current_row [colIdx + 1]);
388 #endif // PCL_INTEGRAL_IMAGE2D_IMPL_H_