Fast Gaussian Blur

Source: Internet
Author: User

Gaussian Blur is one of the most common fuzzy methods, it is widely used in machine vision field.

Gaussian blur for an image is a convolution calculation using a Gaussian window and each point in the image, and the fuzzy effect of different precision can be obtained according to the size of the Gaussian window. The main operational process is convolution, which involves a lot of multiplication and addition. Therefore, although Gaussian blur is very simple in principle, in practice, it is the big head of computational amount in image processing. Therefore, it is very meaningful to find a way to accelerate the Gaussian fuzzy algorithm.

Since the image is two-dimensional, so the image of the Gaussian blur must also be in the 2D dimension (x and Y), assuming that the image pic has k points, the size of the Gaussian window is n*n, then directly to the pic 2D Gaussian Blur will need to do k*n*n multiplication.

Due to the excellent properties of the convolution, the two-dimensional image to do a 2D Gaussian blur is equivalent to the image in order to do the x-axis direction of a Gaussian fuzzy and y-direction of a Gaussian blur, because one-dimensional Gaussian window size is n*1 and 1*n, so the pic do two times 1D Gaussian blur is required 2*k*n times algorithm. With this improvement, the algorithm is more complex from O (n^2) to O (n).

So, can you increase the computational speed and increase the time complexity from O (n) to the constant level O (C)?

Now, let's put the Gaussian blur aside and look at the simplest blur-mean-value blur (box Blur).

The principle of mean ambiguity is the same as Gaussian blur, where the value of each position in the Gaussian window is not exactly equal, and the value of each position in the mean window is 1 (since the mean Blur is the idea of calculating the point blur value with a point and the average of the points around it).

Assuming that the average fuzzy window size is n*1, then the k+1 point to calculate the multiplication results, there are n-2 values in the calculation of the K-point has been calculated.

If n=5, then the K-point to calculate (k-2) * *, (k-1) * *, (k-0) *, (k+1) *and (k+2) * These five values, and the first k+1 points need to calculate (k-1) * *,( k-0) * *, (k+1) *, (k+2) * and (k+3) * These five values, of which three are duplicates, only two need to calculate.

Regardless of boundary and initialization, a one-dimensional mean blur requires only 2 calculations per point, so its time complexity is O (C).

If the Gaussian blur can also use the previous calculation as the mean blur to calculate the current point is good, but the value of the Gaussian window is not exactly equal, but to calculate a similar (k-2) * *, (k-1), (k-0), (k+1) and (k+2) Such results, so the direct copy of the mean fuzzy method is certainly not feasible.

Fortunately, however, we can use multiple mean blur to approximate the result of Gaussian blur. Here, I do not enumerate the specific formula, only from the qualitative point of view to analyze why this can be done: in one dimension, the function image of the mean fuzzy window function is a straight line (covered area is a rectangle), Gaussian Blur window function image is a normal distribution of the image, the rectangle and the rectangle convolution is a triangle, analogy, The rectangular and triangular coils are a convex curve similar to the two-time function ... The more times the convolution is found, the closer the image is to the normal distribution.




The specific value of the mean filter window can be seen in the reference literature and related papers.

The data show that the fuzzy result and Gaussian blur have only 4% error after 4 times of the correct mean value. In engineering practice, we generally use 3-time mean-value ambiguity to approximate Gaussian blur.

Thus, in addition to the previous decomposition of the 2D function into two 1D functions, a K-point image of the pic Gaussian blur requires 2*2*3*k multiplication calculation, time complexity reduced to the constant level O (C).

Tips:

The implementation of fast Gaussian blur requires not only the optimization of the algorithm, but also the optimization of each step in the process of writing the code. For example, when accessing an array, the array is accessed in memory to improve the first-level cache hit rate, multiply-combine the two multiplication and one-time addition into one addition and one multiplication, calculate if the N-squared multiplication of 2, as far as possible to replace the displacement calculation, as far as possible to avoid floating-point operations, Turn repetitive operations into tables and so on. In short, you need to think more to write faster code.

Reference

Http://blog.ivank.net/fastest-gaussian-blur.html

https://fgiesen.wordpress.com/2012/07/30/fast-blurs-1/

https://fgiesen.wordpress.com/2012/08/01/fast-blurs-2/

Fast Gaussian Blur

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.