1. Overview

In this tutorial, we’ll talk about how the blur operation works in images. First, we’ll present kernel convolution, which is the basic operation behind any blur operation. Then, we’ll define two types of blur, the mean and the Gaussian blur, and provide some illustrative examples.

2. Kernel Convolution

The most common operation in the field of computer vision and image processing is kernel convolution.

Formally, convolution is a mathematical operation where two functions are combined to generate a third function that expresses how the shape of one is influenced by the other. Its applications are numerous in various fields like statistics, signal processing, physics, acoustics, and so on. In our case, we focus on kernel convolution, which is the convolution between an input image and a small grid of numbers defined as the kernel.

So, in kernel convolution, we pass the kernel over the input image, transforming each time a pixel of the image based on a specific operation between the kernel and the corresponding pixels of the image. More specifically, for every pixel in the input image, we center the kernel over it and perform an elementwise multiplication between the pixels of the filter and the corresponding pixels of the image. Then, we sum up these values into a single value. Finally, we normalize the results by dividing them by the total value of the kernel to ensure that the intensity of each pixel is not influenced.

Let’s see an example to better illustrate the procedure. We assume that we have an input image I of size 5 \times 5 and a kernel k of size 3 \times 3, and we want to compute the convolution I \star k. Below, we can see some example inputs:

convolution operation

We’ll present one step of the procedure since the rest of the procedure is repeated iteratively for every pixel. Let’s choose the pixel I_{(2, 2)} that is in the second row and column of the image I and is equal to 1 (pink in the image below):

convolution operation 1

As previously presented, we first compute the multiplications between the pixels around the region 3 \times 3 of I_{(2, 2)} and the kernel k. Then we sum the outputs:

S = I_{(1, 1)} \times k_{(1, 1)} + I_{(1, 2)} \times k_{(1, 2)} + I_{(1, 3)} \times k_{(1, 3)} ...
S = 1 \times 1 + 2 \times 2 + 2 \times 3 + 3 \times 3 + 1 \times 2 + 2 \times 1 + 1 \times 1 + 3 \times 1 + 1 \times 1
S = 29

Finally, we divide the output by the sum of the values of the kernel:

I \ast k = \frac{S}{15} = \frac{29}{15} = 1.9

Intuitively, in kernel convolution, we compute a weighted average between regions of the input image and the kernel. In this article, we will see two types of kernels that aim to blur the input image.

3. Mean Blur

If we set all the values of the kernel k to 1, we end up with a mean blur operation to the input image, which is a very simple form of a blur. To better illustrate the mean blur, let’s compute the mean blur convolution of the previous image with a kernel of size 3. We should not forget that we talk about images, and the output pixels should always be integer values. So, we round the output of the final division to the closest integer:

mean example

We can see that the mean blur makes the example image smoother. Below, we can see some examples of mean blurs in a real image with different values of the kernel size k:

mean blur example

We can see that an important problem of mean blur is the fact that it doesn’t take into account the edges of the image. So, after blurring an image, its edges disappear.

4. Gaussian Blur

To deal with the above problem, we can use the Gaussian blur that uses a slightly more complicated kernel, the Gaussian kernel.

Gaussian blur is the most common type of blur since it is edge-preserving. As the name suggests, it behaves like the Gaussian distribution giving more weight to the central pixels. An example Gaussian kernel of size 3 \times 3 has the below format:

gaussian kernel

So, we can see that the major difference between Gaussian blur with the mean blur is the fact that it prioritizes the pixels in the middle of the region. The further we go from the central pixels, the less weight we have in the respective pixel of the input image::

gaussian blur example

We observe that more edges are preserved in contrast with the mean blur operation.

5. Conclusion

In this article, we talked about how the blur operation works in images. First, we introduced the term kernel convolution, which lies at the heart of every blur operation. Then, we presented the mean and the Gaussian blur, along with some examples.

Comments are closed on this article!