Saturday, August 28, 2010

computing integral images (summed area table)



A summed area table (also known as an integral image) is an algorithm for quickly and efficiently generating the sum of values in a rectangular subset of a grid.

The idea behind summed area tables is that you build a two dimensional running sum of the image.
its widely used in the computer vision community when it was used by Viola-Jones object detection framework twenty years after its introduction.


Viola, Paul; Jones, Michael (2002). "Robust Real-time Object Detection". International Journal of Computer Vision. http://research.microsoft.com/~viola/Pubs/Detect/violaJones_IJCV.pdf.

Integral Images is done for GRAY SCALE Image.

In MATLAB, integral images is computed via the following function:
This function computes an integral image
such that the value of intim(r,c)
equals sum(sum(im(1:r, 1:c))
intim = cumsum(cumsum(im,1),2);
A summed area table, or integral
image, can be generated by computing the cumulative sums along the rows of an image and then computing the cumulative sums down the columns. Thus the value at any point (x, y) in the integral image is the sum of all the image pixels above and to the left of (x, y), inclusive.

The integral image is computed rapidly from an input image and is used to speed up the calculation of any upright rectangular area. Used in the SURF implementation

    [rows, cols] = size(intim);
fim = zeros(rows, cols);


[nfilters, fcols] = size(f);
if fcols ~= 5
error('Filters must be specified via an nx5 matrix');
end

f(:,1:2) = f(:,1:2)-1; % Adjust the values of r1 and c1 to save addition
% operations inside the loops below

rmin = 1-min(f(:,1)); % Set loop bounds so that we do not try to
rmax = rows - max(f(:,3)); % access values outside the image.
cmin = 1-min(f(:,2));
cmax = cols - max(f(:,4));

for r = rmin:rmax
for c = cmin:cmax
for n = 1:nfilters

fim(r,c) = fim(r,c) + f(n,5)*...
(intim(r+f(n,3),c+f(n,4)) - intim(r+f(n,1),c+f(n,4)) ...
- intim(r+f(n,3),c+f(n,2)) + intim(r+f(n,1),c+f(n,2)));

end
end

end

examples images to follow:


Original Image

Filtered image with box filter and integral image
an nxm image produces an nxm integral image

No comments:

Post a Comment