Documentation

This is machine translation

Mouseover text to see original. Click the button below to return to the English version of the 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 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 ```

In an integral image, each pixel is the cumulative sum of the pixel directly above it and to its left. For example, in this trivial matrix, the pixel in the original matrix at row 1, column 1 (value 17) would be unchanged in an integral image because you are adding 0s to the value. (The `integralImage` function adds a row of 0s above and to the left of the original matrix.) Calculating the integral image value for pixel (1,2) in the original matrix, you add the pixel above it (0) and the pixel to its left (17): 24 + 17 +0 = 41. Calculating the integral image value for Pixel (1,3) in the originl matrix, you add the pixel above it (0) and the pixel to its left, which has already been summed, 41. Thus the value at pixel (2,4) in the integral image is 1 + 41 + 0 = 42. This process continues for each pixel in the original image, as you can see in the integral image of the original matrix calculated by the `integralImage` function.

`J = integralImage(I)`
```J = 6×6 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 ```

Create sample image.

`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 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` | `string`

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))`.

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.

 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.