Documentation

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.

integralImage

Calculate integral image

Syntax

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

Description

example

J = integralImage(I) calculates the Integral Image , J, from the intensity image, I.

example

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

Examples

collapse all

Create a simple sample image. For this example, sum the 2-by-2 rectangular region starting at row 1, column 3 (value 1) and extending to row 2, column 4 (value 14). In this trivial example, it's easy to calculate the sum of the pixels in the region: 1 + 7 + 8 + 14 = 30.

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

Create an integral image of the sample image. The value of each pixel in the integral image is the sum of the pixel above it and the pixel to its left. Note how integralImage adds a padding row to the top and left sides of the image.

J = integralImage(I)
J = 

     0     0     0     0     0     0
     0    17    41    42    50    65
     0    40    69    77    99   130
     0    44    79   100   142   195
     0    54   101   141   204   260
     0    65   130   195   260   325

Sum the rectangular region in the integral image. In this calculation, you extend the rectangular region you sum. The coordinates of the four corners are: (startRow,startCol),(startRow,endCol+1),(endRow,startCol), and (endRow+1,endCol+1)

regionSum = (J(1,3) + J(3,5)) - (J(1,5) + J(3,3))
regionSum = 30

Create sample image.

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 rotated rectangular region as [x, y, width, height] where x, y
% denote the indices of the top corner of the rectangle. Width and height
% are along 45 degree lines from the top corner.
[x, y, w, h] = deal(3, 1, 3, 2);

Create integral image.

J = integralImage(I, 'rotated');

Compute the sum over the region using the integral image.

regionSum = J(y+w+h,x+w-h+1) + J(y,x+1) - J(y+h,x-h+1) - J(y+w,x+w+1);

Input Arguments

collapse all

Input grayscale image, specified as a real, nonsparse 2-D matrix.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32

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 computation of pixel sums along all image boundaries, the integralImage pads the output integral images as follows:

Integral ImageDescription
Upright integral imageZero-padded on top and left, resulting in size(J) = size(I)+1
Rotated integral imageZero-padded at the top, left, and right, resulting in size(J) = size(I)+[1 2]

If the input image has more than two dimensions (ndims(I)>2), such as for an RGB image, the integralImage function computes the integral image for all 2-D planes along the higher dimensions.

Data Types: char

Output Arguments

collapse all

Integral image, returned as a real, nonsparse matrix of class double. The function zero-pads the top and left side of the integral image so the size of the output integral image is the size as the input image, plus 1, 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)).

More About

collapse all

Integral Image

In an integral image, every pixel is the summation of the pixels above and to the left of it. Using an integral image, you can 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.

References

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

Introduced in R2015b

Was this topic helpful?