Integral Image and Integral Histogram

Integral image article recommendation: http://blog.sina.com.cn/s/blog_4cb0b54301017wwo.html

                               https://blog.csdn.net/u010807846/article/details/50354000


references:

    [1] Viola P., Jones M. J. Rapid Object Detection Using a Boosted Cascade of Simple Features. Computer Vision and Pattern Recognition, 2001, Volume 1, 8-14.
    [2] Lampert C., Blaschko M., Hofmann T. Efficient subwindow search: A branch and bound framework for object localization. IEEE PAMI 31(2009)2129-2142.
    [3] F.Porkili. Integral Histogram: A fast way to extract histograms in cartesian spaces. In Proc.IEEE Conf. on Computer Vision and Pattern Recognition(CVPR), 2005.

In [1], there are two important ideas:

    1 Cascading weak classifiers can form strong classifiers, and the final results can match or even surpass many strong classifiers. This is also a classifier framework that is still commonly used today --- Ensemble Classifier .
    2 In order to detect objects quickly and effectively in real time, the pre-compute concept is used to form an integral image mode. When the pixel value is used, the pixels of a rectangular frame can be obtained by 4 simple table lookups, which is very practical in Real-time. It is also one of the methods still used by many people today.

    Integral image:
    Look at this most primitive thing first. Given an image (preferably grayscale, if color needs to be calculated for each channel). The grayscale values ​​are shown in the following figure:

Figure 1: Image Grayscale
Figure 1 shows the pixels of an image (the pixels inside are all grayscale scales, for the convenience of explanation ,     the grayscale values ​​here are all 1~9). The idea is to add these 9 pixel values ​​directly, which is expressed in mathematical formulas as:
      
Formula 1: i,j represent the position, image represents the image
    Obviously, if it is only for a small area, such addition and subtraction are not very complicated. If this area contains thousands of pixels, it is more complicated to calculate. Therefore, as the computing area increases, the time complexity also increases rapidly.
    Is there a simpler method that can keep the time complexity the same no matter how big the area needs to be calculated, or the change is small. This is the initial consideration of the integral image strategy, minimizing subsequent calculations to achieve real-time results.
    
    The integral image , as the name implies, does the corresponding integral for the pixel value of each point . In fact, the simple expression is that the pixel value of each point is equal to the sum of all the pixel values ​​before it. Convert Figure 1 to an integral image as Figure 2:

Figure 2: Integral image of Figure 1
    Now calculating the value of the depth area in the graph can be easily obtained by using 4 differences: 120 - 42 - 21 + 6 = 63.
    How to use the integral image to calculate the value of any rectangular box? Generally speaking, it is simple to look up the table 4 times, and then a simple "--+" operation can obtain the grayscale sum in the rectangular box.
    explain:

Figure 3: Integral Image Calculation
    区域1 : = sum(A);
    区域2 : = sum(A + B);
    区域3 : = sum(A + C);
    区域4 : = sum(A + B + C + D);
    
    所以,如果需要计算D区域中的灰度和,则
    sum(D) = 区域4 - 区域2 - 区域3 + 区域1 (都是灰度值)。
    很明显,这里仅仅只需要通过查表得到 1、2、3、4点的积分图像的值即可得到。
    
    这其实就是积分图像最妙的地方,通过简单的预计算处理,存储整幅图像的积分图像,通过4次快速查表,便可以得到一个矩形框中的灰度和。下图是计算积分图像的公式:

公式2
    直接利用[1]中的解释:s(x,y)是row的积分值,ii(x,y)就是最终的积分图像。

    正因为积分图像实现简单,速度快,从提出以后,后面相应的出现了更多在此基础上做文章的研究。例如“Sub-Window Search”[2]也是通过利用积分图像的原理,从全局进行深度搜索,最终得到一个比较好的定位。另外,[3]也是在原始的灰度积分图像上做出的一点扩展,将这种快速算法扩展到直方图的计算上来,也可以很好的进行图像的定位。

积分直方图:
    还是利用图1中的灰度作为例子。在积分直方图中,最小的积分单元不再是灰度,而是灰度或者彩色的直方图。如果对于图1中,选择9个bin作为基,则将图1通过转化每个bin的 频率,如图4所示:
积分图像与积分直方图
图4:频率图
    参考直方图的概念[4],不作详细解释为什么会是这样的频率。
    但是,想把上面的图变成积分图的形式,与最初的积分图像不一样的地方在于,并不能把这些数字积分相加起来,而应该把 每一部分的bin进行对应的处理。即bin与bin之间的相加。例如在图中点(1,1)处的bin与点(1,2)处的bin如下图:
积分图像与积分直方图
图5:左图为点(1,1)处原始直方图,右图为点(1,2)处
的原始直方图
    而点(1,2)处的积分直方图为点(1,1)处的原始直方图加上点(1,2)处的原始直方图(对应的bin)相加。得到结果如下图:
积分图像与积分直方图
图6:积分直方图
    在点(1,2)处利用积分的思想,存入的值应该是上图的直方图。以此类推,后面的每一个点的直方图都是前面所有点的直方图的和。
    其实积分直方图的过程包括计算积分以及后续的查表得到某一个区域的值都与积分图像非常的相似。

     心得:
    积分图像的好处就在于能够很快的处理某一个区域的值,但如果预计算包括预存储的空间非常的大,也可能这种空间换时间的方法就不再成为通用的解决办法。


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325703151&siteId=291194637