39 #ifndef PCL_INTEGRAL_IMAGE2D_IMPL_H_
40 #define PCL_INTEGRAL_IMAGE2D_IMPL_H_
45 template <
typename DataType,
unsigned Dimension>
void
48 compute_second_order_integral_images_ = compute_second_order_integral_images;
52 template <
typename DataType,
unsigned Dimension>
void
55 if ((width + 1) * (height + 1) > first_order_integral_image_.size () )
59 first_order_integral_image_.resize ( (width_ + 1) * (height_ + 1) );
60 finite_values_integral_image_.resize ( (width_ + 1) * (height_ + 1) );
61 if (compute_second_order_integral_images_)
62 second_order_integral_image_.resize ( (width_ + 1) * (height_ + 1) );
64 computeIntegralImages (data, row_stride, element_stride);
70 unsigned start_x,
unsigned start_y,
unsigned width,
unsigned height)
const
72 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
73 const unsigned upper_right_idx = upper_left_idx + width;
74 const unsigned lower_left_idx = (start_y + height) * (width_ + 1) + start_x;
75 const unsigned lower_right_idx = lower_left_idx + width;
77 return (first_order_integral_image_[lower_right_idx] + first_order_integral_image_[upper_left_idx] -
78 first_order_integral_image_[upper_right_idx] - first_order_integral_image_[lower_left_idx] );
84 unsigned start_x,
unsigned start_y,
unsigned width,
unsigned height)
const
86 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
87 const unsigned upper_right_idx = upper_left_idx + width;
88 const unsigned lower_left_idx = (start_y + height) * (width_ + 1) + start_x;
89 const unsigned lower_right_idx = lower_left_idx + width;
91 return (second_order_integral_image_[lower_right_idx] + second_order_integral_image_[upper_left_idx] -
92 second_order_integral_image_[upper_right_idx] - second_order_integral_image_[lower_left_idx] );
96 template <
typename DataType,
unsigned Dimension>
unsigned
98 unsigned start_x,
unsigned start_y,
unsigned width,
unsigned height)
const
100 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
101 const unsigned upper_right_idx = upper_left_idx + width;
102 const unsigned lower_left_idx = (start_y + height) * (width_ + 1) + start_x;
103 const unsigned lower_right_idx = lower_left_idx + width;
105 return (finite_values_integral_image_[lower_right_idx] + finite_values_integral_image_[upper_left_idx] -
106 finite_values_integral_image_[upper_right_idx] - finite_values_integral_image_[lower_left_idx] );
112 unsigned start_x,
unsigned start_y,
unsigned end_x,
unsigned end_y)
const
114 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
115 const unsigned upper_right_idx = start_y * (width_ + 1) + end_x;
116 const unsigned lower_left_idx = end_y * (width_ + 1) + start_x;
117 const unsigned lower_right_idx = end_y * (width_ + 1) + end_x;
119 return (first_order_integral_image_[lower_right_idx] + first_order_integral_image_[upper_left_idx] -
120 first_order_integral_image_[upper_right_idx] - first_order_integral_image_[lower_left_idx] );
126 unsigned start_x,
unsigned start_y,
unsigned end_x,
unsigned end_y)
const
128 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
129 const unsigned upper_right_idx = start_y * (width_ + 1) + end_x;
130 const unsigned lower_left_idx = end_y * (width_ + 1) + start_x;
131 const unsigned lower_right_idx = end_y * (width_ + 1) + end_x;
133 return (second_order_integral_image_[lower_right_idx] + second_order_integral_image_[upper_left_idx] -
134 second_order_integral_image_[upper_right_idx] - second_order_integral_image_[lower_left_idx] );
138 template <
typename DataType,
unsigned Dimension>
unsigned
140 unsigned start_x,
unsigned start_y,
unsigned end_x,
unsigned end_y)
const
142 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
143 const unsigned upper_right_idx = start_y * (width_ + 1) + end_x;
144 const unsigned lower_left_idx = end_y * (width_ + 1) + start_x;
145 const unsigned lower_right_idx = end_y * (width_ + 1) + end_x;
147 return (finite_values_integral_image_[lower_right_idx] + finite_values_integral_image_[upper_left_idx] -
148 finite_values_integral_image_[upper_right_idx] - finite_values_integral_image_[lower_left_idx] );
152 template <
typename DataType,
unsigned Dimension>
void
154 const DataType *data,
unsigned row_stride,
unsigned element_stride)
156 ElementType* previous_row = &first_order_integral_image_[0];
157 ElementType* current_row = previous_row + (width_ + 1);
158 memset (previous_row, 0,
sizeof (ElementType) * (width_ + 1));
160 unsigned* count_previous_row = &finite_values_integral_image_[0];
161 unsigned* count_current_row = count_previous_row + (width_ + 1);
162 memset (count_previous_row, 0,
sizeof (
unsigned) * (width_ + 1));
164 if (!compute_second_order_integral_images_)
166 for (
unsigned rowIdx = 0; rowIdx < height_; ++rowIdx, data += row_stride,
167 previous_row = current_row, current_row += (width_ + 1),
168 count_previous_row = count_current_row, count_current_row += (width_ + 1))
170 current_row [0].setZero ();
171 count_current_row [0] = 0;
172 for (
unsigned colIdx = 0, valIdx = 0; colIdx < width_; ++colIdx, valIdx += element_stride)
174 current_row [colIdx + 1] = previous_row [colIdx + 1] + current_row [colIdx] - previous_row [colIdx];
175 count_current_row [colIdx + 1] = count_previous_row [colIdx + 1] + count_current_row [colIdx] - count_previous_row [colIdx];
176 const InputType* element = reinterpret_cast <
const InputType*> (&data [valIdx]);
179 current_row [colIdx + 1] += element->template cast<typename IntegralImageTypeTraits<DataType>::IntegralType>();
180 ++(count_current_row [colIdx + 1]);
187 SecondOrderType* so_previous_row = &second_order_integral_image_[0];
188 SecondOrderType* so_current_row = so_previous_row + (width_ + 1);
189 memset (so_previous_row, 0,
sizeof (SecondOrderType) * (width_ + 1));
191 SecondOrderType so_element;
192 for (
unsigned rowIdx = 0; rowIdx < height_; ++rowIdx, data += row_stride,
193 previous_row = current_row, current_row += (width_ + 1),
194 count_previous_row = count_current_row, count_current_row += (width_ + 1),
195 so_previous_row = so_current_row, so_current_row += (width_ + 1))
197 current_row [0].setZero ();
198 so_current_row [0].setZero ();
199 count_current_row [0] = 0;
200 for (
unsigned colIdx = 0, valIdx = 0; colIdx < width_; ++colIdx, valIdx += element_stride)
202 current_row [colIdx + 1] = previous_row [colIdx + 1] + current_row [colIdx] - previous_row [colIdx];
203 so_current_row [colIdx + 1] = so_previous_row [colIdx + 1] + so_current_row [colIdx] - so_previous_row [colIdx];
204 count_current_row [colIdx + 1] = count_previous_row [colIdx + 1] + count_current_row [colIdx] - count_previous_row [colIdx];
206 const InputType* element = reinterpret_cast <
const InputType*> (&data [valIdx]);
209 current_row [colIdx + 1] += element->template cast<typename IntegralImageTypeTraits<DataType>::IntegralType>();
210 ++(count_current_row [colIdx + 1]);
211 for (
unsigned myIdx = 0, elIdx = 0; myIdx < Dimension; ++myIdx)
212 for (
unsigned mxIdx = myIdx; mxIdx < Dimension; ++mxIdx, ++elIdx)
213 so_current_row [colIdx + 1][elIdx] += (*element)[myIdx] * (*element)[mxIdx];
222 template <
typename DataType>
void
225 if ((width + 1) * (height + 1) > first_order_integral_image_.size () )
229 first_order_integral_image_.resize ( (width_ + 1) * (height_ + 1) );
230 finite_values_integral_image_.resize ( (width_ + 1) * (height_ + 1) );
231 if (compute_second_order_integral_images_)
232 second_order_integral_image_.resize ( (width_ + 1) * (height_ + 1) );
234 computeIntegralImages (data, row_stride, element_stride);
240 unsigned start_x,
unsigned start_y,
unsigned width,
unsigned height)
const
242 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
243 const unsigned upper_right_idx = upper_left_idx + width;
244 const unsigned lower_left_idx = (start_y + height) * (width_ + 1) + start_x;
245 const unsigned lower_right_idx = lower_left_idx + width;
247 return (first_order_integral_image_[lower_right_idx] + first_order_integral_image_[upper_left_idx] -
248 first_order_integral_image_[upper_right_idx] - first_order_integral_image_[lower_left_idx] );
254 unsigned start_x,
unsigned start_y,
unsigned width,
unsigned height)
const
256 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
257 const unsigned upper_right_idx = upper_left_idx + width;
258 const unsigned lower_left_idx = (start_y + height) * (width_ + 1) + start_x;
259 const unsigned lower_right_idx = lower_left_idx + width;
261 return (second_order_integral_image_[lower_right_idx] + second_order_integral_image_[upper_left_idx] -
262 second_order_integral_image_[upper_right_idx] - second_order_integral_image_[lower_left_idx] );
266 template <
typename DataType>
unsigned
268 unsigned start_x,
unsigned start_y,
unsigned width,
unsigned height)
const
270 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
271 const unsigned upper_right_idx = upper_left_idx + width;
272 const unsigned lower_left_idx = (start_y + height) * (width_ + 1) + start_x;
273 const unsigned lower_right_idx = lower_left_idx + width;
275 return (finite_values_integral_image_[lower_right_idx] + finite_values_integral_image_[upper_left_idx] -
276 finite_values_integral_image_[upper_right_idx] - finite_values_integral_image_[lower_left_idx] );
282 unsigned start_x,
unsigned start_y,
unsigned end_x,
unsigned end_y)
const
284 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
285 const unsigned upper_right_idx = start_y * (width_ + 1) + end_x;
286 const unsigned lower_left_idx = end_y * (width_ + 1) + start_x;
287 const unsigned lower_right_idx = end_y * (width_ + 1) + end_x;
289 return (first_order_integral_image_[lower_right_idx] + first_order_integral_image_[upper_left_idx] -
290 first_order_integral_image_[upper_right_idx] - first_order_integral_image_[lower_left_idx] );
296 unsigned start_x,
unsigned start_y,
unsigned end_x,
unsigned end_y)
const
298 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
299 const unsigned upper_right_idx = start_y * (width_ + 1) + end_x;
300 const unsigned lower_left_idx = end_y * (width_ + 1) + start_x;
301 const unsigned lower_right_idx = end_y * (width_ + 1) + end_x;
303 return (second_order_integral_image_[lower_right_idx] + second_order_integral_image_[upper_left_idx] -
304 second_order_integral_image_[upper_right_idx] - second_order_integral_image_[lower_left_idx] );
308 template <
typename DataType>
unsigned
310 unsigned start_x,
unsigned start_y,
unsigned end_x,
unsigned end_y)
const
312 const unsigned upper_left_idx = start_y * (width_ + 1) + start_x;
313 const unsigned upper_right_idx = start_y * (width_ + 1) + end_x;
314 const unsigned lower_left_idx = end_y * (width_ + 1) + start_x;
315 const unsigned lower_right_idx = end_y * (width_ + 1) + end_x;
317 return (finite_values_integral_image_[lower_right_idx] + finite_values_integral_image_[upper_left_idx] -
318 finite_values_integral_image_[upper_right_idx] - finite_values_integral_image_[lower_left_idx] );
322 template <
typename DataType>
void
324 const DataType *data,
unsigned row_stride,
unsigned element_stride)
326 ElementType* previous_row = &first_order_integral_image_[0];
327 ElementType* current_row = previous_row + (width_ + 1);
328 memset (previous_row, 0,
sizeof (ElementType) * (width_ + 1));
330 unsigned* count_previous_row = &finite_values_integral_image_[0];
331 unsigned* count_current_row = count_previous_row + (width_ + 1);
332 memset (count_previous_row, 0,
sizeof (
unsigned) * (width_ + 1));
334 if (!compute_second_order_integral_images_)
336 for (
unsigned rowIdx = 0; rowIdx < height_; ++rowIdx, data += row_stride,
337 previous_row = current_row, current_row += (width_ + 1),
338 count_previous_row = count_current_row, count_current_row += (width_ + 1))
340 current_row [0] = 0.0;
341 count_current_row [0] = 0;
342 for (
unsigned colIdx = 0, valIdx = 0; colIdx < width_; ++colIdx, valIdx += element_stride)
344 current_row [colIdx + 1] = previous_row [colIdx + 1] + current_row [colIdx] - previous_row [colIdx];
345 count_current_row [colIdx + 1] = count_previous_row [colIdx + 1] + count_current_row [colIdx] - count_previous_row [colIdx];
348 current_row [colIdx + 1] += data [valIdx];
349 ++(count_current_row [colIdx + 1]);
356 SecondOrderType* so_previous_row = &second_order_integral_image_[0];
357 SecondOrderType* so_current_row = so_previous_row + (width_ + 1);
358 memset (so_previous_row, 0,
sizeof (SecondOrderType) * (width_ + 1));
360 for (
unsigned rowIdx = 0; rowIdx < height_; ++rowIdx, data += row_stride,
361 previous_row = current_row, current_row += (width_ + 1),
362 count_previous_row = count_current_row, count_current_row += (width_ + 1),
363 so_previous_row = so_current_row, so_current_row += (width_ + 1))
365 current_row [0] = 0.0;
366 so_current_row [0] = 0.0;
367 count_current_row [0] = 0;
368 for (
unsigned colIdx = 0, valIdx = 0; colIdx < width_; ++colIdx, valIdx += element_stride)
370 current_row [colIdx + 1] = previous_row [colIdx + 1] + current_row [colIdx] - previous_row [colIdx];
371 so_current_row [colIdx + 1] = so_previous_row [colIdx + 1] + so_current_row [colIdx] - so_previous_row [colIdx];
372 count_current_row [colIdx + 1] = count_previous_row [colIdx + 1] + count_current_row [colIdx] - count_previous_row [colIdx];
375 current_row [colIdx + 1] += data[valIdx];
376 so_current_row [colIdx + 1] += data[valIdx] * data[valIdx];
377 ++(count_current_row [colIdx + 1]);
383 #endif // PCL_INTEGRAL_IMAGE2D_IMPL_H_