The algorithm of Gaussian Blur

Source: Internet
Author: User

Transferred from:

Typically, the image processing software provides a "blur" (blur) filter that blurs the image.

There are many kinds of "fuzzy" algorithms, one of which is called "Gaussian Blur" (Gaussian Blur). It uses the normal distribution (aka "Gaussian Distribution") for image processing.

This article describes the "Gaussian blur" algorithm, and you will see that this is a very simple and understandable algorithm. In essence, it is a data smoothing, suitable for many occasions, and image processing provides an intuitive application example.

The principle of Gaussian blur

The so-called "blur" can be understood as each pixel takes the average of the surrounding pixels.

, 2 is the middle point, and the surrounding point is 1.

The "Middle point" takes the average of "surrounding points" and becomes 1. In numerical values, this is a "smoothing". On the graph, it is equivalent to producing a "blur" effect, and the "middle point" loses detail.

Obviously, when you calculate the average, the greater the range, the stronger the blur effect.

The above is the original image, the blur radius of 3 pixels, the blur radius of 10 pixels effect. The larger the blur radius, the more blurred the image. From a numerical point of view, the smoother the value is.

The next question is, since each point takes the average of the surrounding pixels, how should the weights be assigned?

If you use simple averages, it is obviously not very reasonable, because the images are contiguous, the closer the point relationship is, the farther away the point relationship becomes. Therefore, the weighted average is more reasonable, the closer the point weight is larger, the farther away the point weight smaller.

Second, the weight of the normal distribution

The normal distribution is obviously a desirable weight distribution pattern.

On the graph, the normal distribution is a bell-shaped curve, the closer the center, the greater the value, the farther away from the center, the smaller the value.

When we calculate the mean, we just need to use the "center point" as the origin, and the other points to assign weights according to their position on the normal curve, we can get a weighted average value.

Three, Gauss function

The normal distribution above is one-dimensional and the images are two-dimensional, so we need a two-dimensional normal distribution.

The density function of the normal distribution is called "Gaussian function" (Gaussian functions). Its one-dimensional form is:

Where μ is the mean value of X and Σ is the variance of x. Because the center point is the origin point when calculating the mean, μ equals 0.

According to a Gaussian function, the Ivigos function can be deduced:

With this function, you can calculate the weight of each point.

Four, the weight matrix

Assuming the coordinates of the center point are (0,0), the coordinates of the nearest 8 points are as follows:

Farther points and so on.

To calculate the weight matrix, you need to set the value of Σ. Assuming σ=1.5, the weight matrix with a blur radius of 1 is as follows:

The sum of the weights of these 9 points equals 0.4787147, and if you only calculate the weighted average of the 9 points, you must also make their weights equal to 1, so the above 9 values are divided by 0.4787147 respectively to get the final weight matrix.

V. Calculation of Gaussian Blur

With the weight matrix, we can calculate the Gaussian blur value.

Assuming the existing 9 pixels, the grayscale value (0-255) is as follows:

Multiply each point by its own weight value:


Adding these 9 values is the Gaussian blur value of the center point.

This process is repeated for all points and the Gaussian blur image is obtained. If the original picture is a color image, you can make Gaussian blur for RGB three channels respectively.

Vi. processing of boundary points

What if a point is at the boundary and there are not enough dots around it?

One workaround is to copy the existing points to the corresponding position on the other side to simulate the complete matrix.

Vii. Reference Documents

Gaussian Blur without using 3rd party libraries


The algorithm of 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: 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.