主要内容

integralImage

计算2-D积分图像

Description

我nanintegral image,每个像素表示相应的输入像素的累积总和,上面和输入像素的左侧所有像素。

积分图像使您能够快速计算图像子区域的求和。子区域求和可以在恒定时间内作为整体图像中仅四个像素的线性组合计算,而不论子区域的大小如何。通过Viola-Jones算法普及了整体图像的使用[1]

例子

j= integralImage(计算积分图像从图像。函数零板在输出积分图像的顶部和左侧,j

例子

j= integralImage(,,,,orientation用以下方向计算积分图像orientation

Examples

Collapse all

创建一个简单的示例矩阵。

i =魔术(5)
i =5×517 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9

Calculate the integral image of the sample matrix. These steps show how the first few values in the original matrix map to values in the integral image. Note that the pixel with (row, column) coordinate (r,,,,C)in the original image corresponds to the pixel with coordinate (r+1,C+1) in the integral image.

  • 这first row and column in the integral image are all0s。

  • 这pixel in the original matrix at coordinate (1, 1) with value 17 is unchanged in the integral image because there are no other pixels in the summation. Therefore, the pixel in the integral image at coordinate (2, 2) has the value 17.

  • 原始矩阵中的像素在坐标(1,2)映射到积分图像中的像素(2,3)。该值是原始像素值(24),其上方的像素(0)的总和,以及其左侧的像素(17):24 + 17 + 0 = 41。

  • 这pixel in the original matrix at coordinate (1, 3) maps to the pixel (2, 4) in the integral image. The value is the summation of the original pixel value (1), the pixel above it (0), and the pixels to its left (which have already been summed to 41). Thus the value at pixel (2,4) in the integral image is 1 + 41 + 0 = 42.

j= integralImage(I)
j=6×60 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

Read a grayscale image into the workspace. Display the image.

i =imread('pout.tif');imshow(i)

Compute the integral image.

j = intemallimage(i);

使用drawrectangletool to select a rectangular subregion. The tool returns aRectangleobject.

d = drawrectangle;

Verticesproperty of theRectangle对象将顶点的坐标存储为4 by-2矩阵。从顶部开始,然后沿顺时针方向开始,从而排序顶点。将矩阵分为两个载体,其中包含行和列坐标。由于积分图像在顶部和左侧为零,因此将行和列坐标增加1以检索积分数组的相应元素。

r =地板(d.vertices(:,2)) + 1;c =地板(d.vertices(:,1)) + 1;

通过组合积分图像的四个像素来计算矩形子区域中所有像素的总和。

区域= J(R(1),C(1))-J(R(2),C(2)) + J(r(3),C(3))-J(r(4),C(r(4),C(r(4)4))
区域= 613092

创建一个简单的示例矩阵。

i =魔术(5)
i =5×517 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9

Create an integral image with a rotated orientation.

j= integralImage(I,“旋转”
j=6×70000000017 24 1 8 15 0 17 64 47 40 38 39 15 64 74 91 104 105 76 39 74 105 149 188 183 130 76 105 170 232 272 236 195 130

定义旋转的矩形子区域。此示例指定了原始图像中坐标处的顶角(1,3)的子区域。子区域的旋转高度为1,宽度为2。

r= 1; c = 3; h = 1; w = 2;

Get the value of the four corner pixels of the subregion in the integral image.

regionBottom = J(r+w+h,c-h+w+1);regiontop = j(r,c+1);regionleft = J(r+H,C-H+1);RegionRight = J(R+W,C+W+1);regioncorners = [regionbottom regiontop regionleft regionright]
regionCorners =1×4105 0 24 39

Calculate the sum of pixels in the subregion by summing the four corner pixel values.

区域= regionbottom + regiontop -regionleft-区域右
区域= 42

我nput Arguments

Collapse all

图像,指定为任何维度的数字阵列。如果输入图像具有两个以上的维度(ndims(i)> 2),,,,such as for an RGB image, thenintegralImage计算沿较高维度的所有2D平面的积分图像。

Data Types:单身的|double|int8|int16|int32|uint8|uint16|UINT32

图像方向,指定为'直立'or“旋转”。我f you set the orientation to“旋转”, 然后integralImage返回在旋转45度的矩形上计算总和的积分图像。

Data Types:CHar|string

Output Arguments

Collapse all

我ntegral image, returned as a numeric matrix. The function zero-pads the integral image according to theorientationof the image. Such sizing facilitates the computation of pixel sums along image boundaries. The integral image,j,,,,is essentially a padded version of the valueCumsum(cumsum(I,2))

我mage Orientation Size of Integral Image
Upright integral image Zero-padded on top and left.size(J) = size(I)+1
旋转的整体图像 Zero-padded at the top, left, and right.size(J) = size(I)+[1 2]

Data Types:double

Algorithms

Collapse all

整体图像Summation

Every pixel in an integral image represents the summation of the corresponding input pixel value with all input pixels above and to the left of the input pixel. BecauseintegralImage零填充所得的积分图像,带有(行,列)坐标的像素(m,,,,n)in the original image maps to the pixel with coordinate (m+1,n+1) in the integral image.

在图中,输入图像中的当前像素是坐标处的深绿色像素(4,5)。All pixels in the input image above and to the left of the input pixel are colored in light green. The summation of the green pixel values is returned in the integral image pixel with coordinate (5, 6), colored in gray.

integralImageperforms a faster computation of the integral image by summing pixel values in both the input image and the integral image. Pixel (m,,,,n)in integral imagej是仅四个像素的线性组合:一个来自输入图像和整体图像的三个先前计算的像素。

j(m,n) = J(m,n-1) + J(m-1,n) + I(m-1,n-1) - J(m-1,n-1)

该图显示,在计算灰色像素的积分图像时,总和中包含哪些像素。绿色像素添加到总和和红色像素中减去总和。

Rotated Integral Image Summation

我f you specify the imageorientation作为“旋转”,然后在积分图像中的像素表示相应的输入像素值的求和,所有输入像素的对角像素都在输入像素上方。integralImageperforms the summation along diagonal lines. This approach is less computationally intensive than rotating the image and calculating the integral image in rectilinear directions.

在图中,输入图像中的当前像素是坐标处的深绿色像素(4,5)。输入图像中的所有像素在对角上方上方的像素上方都颜色为浅绿色。绿色像素值的总和在具有灰色颜色的坐标(5,6)的积分图像像素中返回。

integralImageperforms a faster computation of the rotated integral image by summing pixel values in both the input image and the integral image. Pixel (m,,,,n)in integral imagejis a linear combination of only five pixels: two from the input image and three previously-calculated pixels from the integral image:

j(m,n) = J(m-1,n-1) + J(m-1,n+1) - J(m-2,n) + I(m-1,n-1) + I(m-2,n-1)

该图显示,在计算灰色像素的积分图像时,总和中包含哪些像素。绿色像素添加到总和和红色像素中减去总和。

我mage Subregion Summation

直立方向的子区域,左上坐标(m,,,,n),,,,HeightH,,,,and widthwin the original image has the summation:

区域= J(M – 1,N – 1)+J(M+H – 1,N+W – 1) - J(M+H – 1,N – 1) - J(M-1,N+W-1)

例如,在下面的输入图像中,蓝色阴影区域的汇总为:46 - 22 - 20 + 10 = 14。计算减去上方和左侧的区域。添加重叠面积以补偿双重减法。

A subregion in an rotated orientation uses a different definition of height and width[2]。地区的总和nis:

regionSum = J(m+h+w,n-h+w+1) + J(m,n+1) - J(m+h,n-h+1) - J(m+w,n+w+1)

References

[1]Viola, P., and M. 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. Vol. 1, pp. 511–518.

[2]Lienhart, R., and J. Maydt. "An Extended Set of Haar-like Features for Rapid Object Detection".Proceedings of the 2002 IEEE International Conference on Image Processing。Sept. 2002. Vol. 1, pp. 900–903.

Extended Capabilities

版本历史记录

我ntroduced in R2015b