Tutorial Example

Understand Gaussian Blur Algorithm: A Beginner Guide – Deep Learning Tutorial

Gaussian blur algorithm is common used in image processing filed. In this tutorial, we will introduce how to use this algorithm to blur an image for beginners.

Formula of Gaussian distribution

As to 1-demension data x, Gaussian distribution is:

where σ is variance of x,  mean of x is 0.

The distribution is:

As to 2-demenison data x, Gaussian distribution will be:

The distribution of it is:

How to blur an image with Gaussian distribution?

The key idea is to adjust the center pixel data by its near pixels.

For example, see image below.

The center pixel value is 2.  In order to blur it, we can average its near pixels data to replace its value.

If the raduis = 1. the value of center pixel is: (1 + 1 + 1 + 1 + 1 + 1 + 1 + 1) / 8 = 1.

Blur image above, we will get an image below:

However, averaging all near pixels data is not a good solution, we should assign different weights to them.

Assign different weights to near pixels

Seeing image below, the data of each pixel is:

Here, the center pixel data is 25, radius = 1. The coordination of these pixels are:

To assign different weights to near pixels, we can use Gaussian Distribution.

In image proccessing, we will use 2-D gaussian distribution.

Suppose σ = 1.5, and mean = 0

As to center pixel, the coordination is (0, 0) ,  the probability is:

p(0,0)  = 1 / (2πσ2) =  0.0707355

p(-1,1) = 1 / (2πσ2) × e-(1+1)/(2σ2)= 0.0453542

Different probabilities of pixels are:

However, sum all probabilities, we can find:

0.0453542 + 0.0566406 + …… + 0.0453542 = 0.4787147, which is not equivlent to 1. So we have to normalize them.

Normalize all probabilities

Normalize all probabilities, we will get weight of each pixel.

As to center pixel, the weight of it will be:

w(0,0) = 0.0707355 / 0.4787147 = 0.147761

The weight of each pixel is below:

Then we can calculate the blured value of each pixel by its weight.

The computed value is:

We blur this image successfully by Gaussian Distribution.

Here we should notice:

To use gaussian distribution to blur an image, these variables will affect the blured effect.

mean:  we usually set it to 0.

σ: we usually set it to 0 or 1.5.

radius: it means we will use how many near pixels to blur center pixel.

If radius = 1: number of near pixels is 8.

If radius = 2: the number is 24.

The more bigger of radius , the image will be more blurred. Here is an example.

We will find when radius = 10, the image will be more blurred than radius = 3.