Skip to content
Browse files

Faster version of integral image (2.5 ms, vs. 3 ms).

  • Loading branch information...
1 parent 4854370 commit f2eacf39edd9f147e80f9f601c5154eafbd97276 edrosten committed Apr 1, 2009
Showing with 12 additions and 10 deletions.
  1. +12 −10 cvd/integral_image.h
View
22 cvd/integral_image.h
@@ -35,27 +35,29 @@ namespace CVD
/// @param in The source image.
/// @param out The source image.
/// @ingroup gVision
+
template<class S, class D> void integral_image(const SubImage<S>& in, SubImage<D>& out)
{
if( in.size() != out.size())
throw Exceptions::Vision::IncompatibleImageSizes("integral_image");
-
+
+ out[0][0] = in[0][0];
//Do the first row.
- D sum = 0;
- for(int x=0; x < in.size().x; x++)
- {
- sum += in[0][x];
- out[0][x] = sum;
- }
+ for(int x=1; x < in.size().x; x++)
+ out[0][x] =out[0][x-1] + in[0][x];
+
+ //Do the first column.
+ for(int y=1; y < in.size().y; y++)
+ out[y][0] =out[y-1][0] + in[y][0];
//Do the remainder of the image
for(int y=1; y < in.size().y; y++)
{
- D sum = 0;
+ D sum = in[y][0];
- for(int x=0; x < in.size().x; x++)
+ for(int x=1; x < in.size().x; x++)
{
- sum += in[y][x];
+ sum+= in[y][x];
out[y][x] = sum + out[y-1][x];
}
}

0 comments on commit f2eacf3

Please sign in to comment.
Something went wrong with that request. Please try again.