J = integralImage(I)
J = integralImage(I,orientation)
An integral image lets you rapidly calculate summations over image subregions. Use of integral images was popularized by the Viola-Jones algorithm . Integral images facilitate summation of pixels and can be performed in constant time, regardless of the neighborhood size.
I— Intensity image
Intensity image, specified as an M-by-N grayscale image. This value can be any numeric class.
orientation— Image orientation
Image orientation, specified as
If you set the orientation to
the integral image for computing sums over rectangles rotated by 45
degrees. To facilitate easy computation of pixel sums along all image
boundaries, the output integral images are padded as follows:
|Upright integral image — Zero-padded on top and left,
resulting in |
|Rotated integral image — Zero-padded at the top, left,
and right, resulting in |
Integral image. The function zero-pads the top and left side
of the integral image. The class of the output is
Compute the integral image and use it to compute the sum of pixels over a rectangular region of an intensity image.
Create an image matrix.
I = magic(5)
I = 5×5 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9
Define rectangular region as [startingRow, startingColumn, endingRow, endingColumn].
[sR sC eR eC] = deal(1,3,2,4);
Compute the sum over the region using the integral image.
J = integralImage(I); regionSum = J(eR+1,eC+1) - J(eR+1,sC) - J(sR,eC+1) + J(sR,sC)
regionSum = 30
An integral image helps you rapidly calculate summations over image subregions. Every pixel in an integral image is the summation of the pixels above and to the left of it.
To calculate the summation of a subregion of an image, you can use the corresponding region of its integral image. For example, in the input image below, the summation of the shaded region becomes a simple calculation using four reference values of the rectangular region in the corresponding integral image. The calculation becomes, 46 – 22 – 20 + 10 = 14. The calculation subtracts the regions above and to the left of the shaded region. The area of overlap is added back to compensate for the double subtraction.
In this way, you can calculate summations in rectangular regions rapidly, irrespective of the filter size.
 Viola, Paul and Michael J. Jones, “Rapid Object Detection using a Boosted Cascade of Simple Features”, Proceedings of the 2001 IEEE Computer Society Conference on Computer Vision and Pattern Recognition, 2001. Volume: 1, pp.511–518.