If you are not familiar with the working of integral image and how to work with them, you can follow this guide.
How to Work with Integral Images in MATLAB?
We can work with integral images in MATLAB using the built-in integralImage() function that allows us to compute the integral images from the given image or data set. This function accepts an image or a data set as a mandatory input parameter and calculates an integral image corresponding to the input.
Syntax
We can use the integralImage() function in MATLAB through the following syntaxes:
J = integralImage(I,orientation)
Here,
- The function J = integralImage(I) is responsible for computing an integral image from the given image I. This function zero-pads the left and top sides of the created integral image J.
- The function J = integralImage(I,orientation) is responsible for computing an integral image with the orientation denoted by variable orientation.
Example 1: How to Create an Integral Image in MATLAB?
This MATLAB code creates an integral image from the given 10-by-10 matrix of random numbers using the integralImage() function.
J = integralImage(I)
The given output shows the values of the matrix I.
The following output values represent the calculated integral image J.
- The first row as well as first column of the created integral image are 0s.
- The (1,1) value of the original matrix maps the (2,2) value of the integral image and it is unchanged because it is added to 0 so 62+0=62.
- The (1,2) value of the original matrix maps the (2,3) value of the integral image and it is calculated by adding it to its top and left value so 62+70+0=132 and so on.
Example 2: How to Create an Integral Image in MATLAB With Upright Orientation?
In this example, we use the integralImage() function to create an integral image from the given matrix with an upright orientation.
J = integralImage(I,"upright")
Conclusion
In an integral image, every pixel represents the cumulative sum of its left and above pixels. It is commonly used for calculating the summation over the subregion of an image. MATLAB allows us to calculate an integral image corresponding to an image or data set using the integralImage() function. This tutorial has provided in detail the functionality of the integralImage() function using different syntaxes with an example for each syntax.