Compute integral image


  • J = integralImage(I)


J = integralImage(I) computes an integral image of the input intensity image, I. The function zero-pads the top and left side of the output integral image, J. The resulting size of the output integral image equals:

size(J) = size(I) +1

Such sizing facilitates easy computation of pixel sums along all image boundaries. The integral image, J, is essentially a padded version of the value cumsum(cumsum(I,2))."

An integral image lets you rapidly calculate summations over image subregions. Use of integral images was popularized by the Viola-Jones algorithm [1]. Integral images facilitate summation of pixels and can be performed in constant time, regardless of the neighborhood size.

Code Generation Support:
Supports MATLAB® Function block: Yes

Code Generation Support, Usage Notes, and Limitations

Input Arguments


Intensity image. This value can be any numeric class.

Output Arguments


Integral image. The function zero-pads the top and left side of the integral image. The class of the output is double.


expand all

Compute an Integral Image

Compute the integral image and use it to compute the sum of pixels over a rectangular region of an intensity image.

I = magic(5)

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)

More About

expand all


How Integral Image Summation Works

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.


[1] 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.

Was this topic helpful?