Understanding super fast blur algorithm

后端 未结 3 731
情书的邮戳
情书的邮戳 2021-02-03 11:47

I\'m trying to understand the algorithm behind the super fast blur algorithm. Below is the port to java that works with android as a test. Looks like this version makes some opt

3条回答
  •  耶瑟儿~
    2021-02-03 12:44

    This box blur algorithm is outlined in this paper from 2001.

    What it's basically doing is blurring the image twice; first in the horizontal direction, and then in the vertical direction. The end result is the same as if you had calculated the convolution of the image with a square box 2r+1 pixels across (i.e., from x-r to x+r, and from y-r to y+r at each point).

    AT each step, the blurred pixel value is simply the average of all the pixels in this range. This can be calculated quickly by keeping a running total at each point. When you move the range to the right (down) one pixel, you subtract the pixel at the left (top) end and add the pixel at the right (bottom) end. You still have to divide these running totals by 2r+1, but this can be sped up by precomputing fixed-point values of n/(2r+1) for (0≤n<256) and storing them in dv[] (with an 8-bit fractional part).

    The short summation loops at the start of each scan are just there to calculate the initial values of the running total.

    And with a bit of juggling with max() and min() to avoid accessing out-of-range pixels, that's about all there is to it.

提交回复
热议问题