Matlab

How to Work with Integral Images in MATLAB

An integral image refers to an image in which pixels are the sum of pixels above and left to them. In other words, we can say that in an integral image, each pixel represents the cumulative sum of its above and left pixels. It is widely used for computing the submission over the subregion of an image. The subregion summations are computed keeping the time constant in the form of a linear combination of the four pixels of the integral image.

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

I = randi(100,10)
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.

I = randi(100,4)
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.

About the author

Komal Batool Batool

I am passionate to research technologies and new ideas and that has brought me here to write for the LinuxHint. My major focus is to write on programming languages and computer science related topics.