integralImage() - Image Processing
J = integralImage(I) calculates
the Integral Image , J,
from the intensity image, I. exampleJ = integralImage(I,orientation) calculates
the integral image with the orientation specified by orientation.
Syntax
J = integralImage(I) exampleJ = integralImage(I,orientation) example
Example
Use Integral Image to Compute Region SumsOpen This Example
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
Compute Integral Image with Rotated OrientationOpen This Example
Create sample image.I = magic(5)
% 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);
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 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);
Output / Return Value
Limitations
Alternatives / See Also
Reference