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

By | November 6, 2019

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:

Gaussian formula 1 demension

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

The distribution is:

1-D Gaussian distribution with mean 0 and variance 1

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

2-d gaussian distribution formula

The distribution of it is:

2-D Gaussian distribution with mean = (0, 0) and variance = 1

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:

Blur image data with its near pixels

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:

pixel data in image

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

pixel position in image

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

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

2-d gaussian distribution formula

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:

Different probabilities of pixels

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:

the weight of each pixel

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

calculate blured value of each pixel

The computed value is:

the blured pixel data value

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.

the blured effect on different radius value

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

Leave a Reply