This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Calculate 3-D integral image


J = integralImage3(I)



J = integralImage3(I) calculates the integral image, J, from the input intensity image, I.


collapse all

Create a 3-D input image.

I = reshape(1:125,5,5,5);

Define a 3-by-3-by-3 sub-volume as [startRow, startCol, startPlane, endRow, endCol, endPlane].

[sR, sC, sP, eR, eC, eP] = deal(2, 2, 2, 4, 4, 4);

Create an integral image from the input image and compute the sum over a 3-by-3-by-3 sub-volume of I.

J = integralImage3(I);
regionSum = J(eR+1,eC+1,eP+1) - J(eR+1,eC+1,sP) - J(eR+1,sC,eP+1) ...
        - J(sR,eC+1,eP+1) + J(sR,sC,eP+1) + J(sR,eC+1,sP) ... 
        + J(eR+1,sC,sP) -J(sR,sC,sP)
regionSum = 1701

Verify that the sum of pixels is accurate.

sum(sum(sum(I(sR:eR, sC:eC, sP:eP))))
ans = 1701

Input Arguments

collapse all

Input intensity image, specified as a real, nonsparse 3-D array of any numeric class.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32

Output Arguments

collapse all

Integral image, returned as a real, nonsparse matrix of class double. The function zero-pads the top, left and along the first plane, resulting in size(J) = size(I) + 1. side of the integral image. The class of the output is double. The resulting size of the output integral image equals: 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(cumsum(I),2),3).

More About

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.

Introduced in R2015b