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

I — Intensity image

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

orientation — Image orientation'upright' (default) | 'rotated'

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:

Algorithms

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.