This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Integral image


J = integralImage(I)
J = integralImage(I,orientation)


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.

J = integralImage(I,orientation) computes the integral image with the specified orientation.

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.

Input Arguments

collapse all

Intensity image, specified as an M-by-N grayscale image. This value can be any numeric class.

Image orientation, specified as 'upright' or 'rotated'. If you set the orientation to 'rotated', integralImage returns 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 size(J) = size(I) + 1
Rotated integral image — Zero-padded at the top, left, and right, resulting in size(J) = size(I) + [1 2]

Output Arguments


Integral image. The function zero-pads the top and left side of the integral image. The class of the output is double. 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)).


collapse all

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 =

    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 =



collapse 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.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced in R2012a

Was this topic helpful?