[Digital image processing] FIG fast mean filter based on integrator

Disclaimer: This article is a blogger original article, reproduced, please indicate the source https://blog.csdn.net/C2681595858/article/details/85011951

First, the experiment content

Here Insert Picture DescriptionHere Insert Picture Description

Second, the theoretical preparation

  • What is the integral image?

    • FIG integral image I S are the same size of the image thereto, S of each pixel S (u, v) are stored in I (u, v) of all the pixels of the top left corner and the grayscale values. As shown below:
      Here Insert Picture Description
    • Integral image can increment calculation, just to be original while scanning.
      Here Insert Picture Description
  • Specific method of performing fast mean filter based on integrator of FIG.

    • Provided filter template size 2w + 1, the result is filtered image O, then:
      O ( in , v ) = 1 with [ S ( in + w , v + w ) + S ( in w 1 , v w 1 ) S ( in + w , v w 1 ) S ( in w 1 , v + w ) ] O(u,v) =\frac{1}{z}[S(u+w,v+w)+S(u-w-1,v-w-1)-S(u+w,v-w-1)-S(u-w-1, v+w)]
      where with with means a number of filtering template pixel i.e. 2 w + 1 ) 2 (2w + 1) ^ 2 .
  • Why this has nothing to do filtering efficiency mode and window size? This can be done really mean filter it?

    • First, we look at it illustrated what to do every step:
      Here Insert Picture Description
    • Referring to FIG be appreciated that the formula O ( u , v ) = 1 z [ S ( u + w , v + w ) + S ( u w 1 , v w 1 ) S ( u + w , v w 1 ) S ( u w 1 , v + w ) ] O(u,v) =\frac{1}{z}[S(u+w,v+w)+S(u-w-1,v-w-1)-S(u+w,v-w-1)-S(u-w-1, v+w)] .
      First, S (u + w, v +are all gradation values and green frame, then S (uw-1, vw-of all the grayscale values and the black box. They two together is twice the value of all the gray and green frame in which the black box is added. Then S (u + w, vw-frame and the gray-red, red frame is subtracted from the previous results, since the black box is a left plus twice subtracted once, and then the non-red box black box is part of the lost. Then S (uw-1, v +as a yellow frame portion, the remainder of subtracting a black box, a black box frame portion by subtracting the non-yellow, left after only part of the blue background is just what we filtering template covering part of the pixel value of the sum. Then multiplied by 1 / z is a mean filter.
  • When to expand the edge?

    • In calculating the final image from the integrated view of the need to expand over the edge of the image, that when it is appropriate to expand the edge?
    • 有两个地方可以进行边缘拓展,第一个是计算积分图之前对原图像进行边缘拓展,第二个是对积分图进行边缘拓展。
    • 这里为了加速滤波结果和不加速均值滤波结果相同,应该采取对原图像进行边缘拓展。

三、实验环境

  • 操作系统及版本:windows10
  • 编译软件及版本:vs2017+opencv
  • 使用的计算机语言:c++

四、实验过程

  • 就是把上面的理论转换成代码。
  • 需要考虑下面一些问题:
    1、 计算积分图的时候,下面公式中的v-1会导致数组越界访问,需要特殊处理。
    Here Insert Picture Description
    2、进行滤波的时候,下面公式中有减号的项会导致数组越界访问,需要特殊处理。
    Here Insert Picture Description
    实现代码:
    基于积分图的快速均值滤波

五、实验结果

  • 原图vs滤波后
    Here Insert Picture Description

六、实验总结

  • 本来这次应该是最简单的实验,但我却把它做成了最复杂的实验,本来可以1小时完成的作业我却花了相当于一天时间,导致这个的原因是忽视数据类型,debug缺乏经验。
  • 我写完代码,感觉非常良好,自信满满,觉得可以上交了,运行试下吧,结果如下:
    Here Insert Picture Description
    直接不给我任何结果,很纳闷了,然后重新读代码,一遍又一遍,找不出什么问题啊。逻辑全正确,然后回想一下好像什么时候遇到过这种尴尬的场面。原因好像是float强制转int,导致0-1之间的数全0。好了完美,将车祸现场改成如下形式:
    Here Insert Picture Description
    好了,这下总可以了吧。运行下:
    Here Insert Picture Description
  • 我**不干了。。。。。。。。。。冷静冷静我们休息下再看。这一休息就是3天。
  • Well, enjoy coding! Finally attack him again, determined to win the enemy camp. So first a small picture directly, the output of each of the intermediate results, and manually verified. Site are as follows: output the edge image gray value, integral image, the image intensity filtered after treatment.
    Here Insert Picture Description
    After calculation verified, errors are found in the filtered image, so that part of the code focused look. No problem repeatedly see the logic in the output of each details of the calculation to see where the problem is, eventually found that the above formula was a problem. The reason is that
    Here Insert Picture Description
    red line a few places left parenthesis, leading to the calculation error, modify over the task is completed.
  • To summarize: details are important, in particular data type resulted in a change of accuracy, this can not be overstated how attentive.

Guess you like

Origin blog.csdn.net/C2681595858/article/details/85011951