Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Faster version of integral image (2.5 ms, vs. 3 ms).
  • Loading branch information
edrosten committed Apr 1, 2009
1 parent 4854370 commit f2eacf3
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions cvd/integral_image.h
Expand Up @@ -35,27 +35,29 @@ namespace CVD
/// @param in The source image. /// @param in The source image.
/// @param out The source image. /// @param out The source image.
/// @ingroup gVision /// @ingroup gVision

template<class S, class D> void integral_image(const SubImage<S>& in, SubImage<D>& out) template<class S, class D> void integral_image(const SubImage<S>& in, SubImage<D>& out)
{ {
if( in.size() != out.size()) if( in.size() != out.size())
throw Exceptions::Vision::IncompatibleImageSizes("integral_image"); throw Exceptions::Vision::IncompatibleImageSizes("integral_image");


out[0][0] = in[0][0];
//Do the first row. //Do the first row.
D sum = 0; for(int x=1; x < in.size().x; x++)
for(int x=0; x < in.size().x; x++) out[0][x] =out[0][x-1] + in[0][x];
{
sum += in[0][x]; //Do the first column.
out[0][x] = sum; 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 //Do the remainder of the image
for(int y=1; y < in.size().y; y++) 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]; out[y][x] = sum + out[y-1][x];
} }
} }
Expand Down

0 comments on commit f2eacf3

Please sign in to comment.