Image Convolution.

Vin_itall
Bleep-Bloop
Published in
3 min readOct 26, 2019

The ma(th)gic behind blurs in image processing.

Whenever you choose a filter to apply on your selfies, this is what goes on under the hood to provide your image that extra bit of glamour that you think you lack. However, it takes a lot more than a blur to make you look better but it’s definitely a part of the process.

Applying blur to an image means convolving(In mathematics, convolution means to combine two mathematical functions to give a third function) the image with a kernel(a square matrix of pixels with predefined values depending on the type of blur).

Box blur and Gaussian blur are some of the most commonly used blurs in the the field of image processing.

Box Blur

Box blur is also known as a box linear filter or Mean blur.

The Box blur works as follows,

Applying Box Blur On An Image.

In the first step, the kernel is mapped onto our input image and with the pixel of interest (‘28’) in the center.

Then an intermediate matrix is generated of the size of the kernel, which is then used to calculate the average.

This average value is then rounded and substituted in the place of the pixel and the process is repeated for each pixel in the region of interest.

So, basically applying a Box blur is substituting a pixel’s value with the average value of all the pixel’s around it and the pixel itself.

Gaussian Blur

Where the values of pixels in an Box blur kernel is all unity, the pixel values of a Gaussian Kernel depends on the Gaussian function.

Gaussian Function For n Dimensions

Where σ is the standard deviation of the Gaussian Distribution, which is a bell shaped curve. Standard deviation represents the width of the distribution. In terms of the blur it means that higher the value of standard deviation larger the value carried by the peripheral pixels and the blurrier the resulting image will be.

Source : Wikipedia

The following is how a Gaussian Blur is applied to an image,

Applying Gaussian Blur On An Image.

The process is same as when a Box blur is applied to an image, just the kernel used here changes.

Applying Gaussian blur to an image is equivalent to substituting the pixel’s value with the weighted average of the values of the pixels in it’s neighborhood in the output image.

As you can see the Gaussian blur gives the maximum weight to the pixel(center) itself and the least to the corners and therefore is more edge preserving than Box blur.

A larger standard deviation will require a larger kernel to represent it and therefore a lot more pixels will contribute to the weighted average than the kernel with smaller standard deviation and the output image will therefore be blurrier as compared to Gaussian blur applied with kernel representing a smaller standard deviation.

Great! Now you know what made your teenage face appear smoother than it was. Keep following…Bleep-Bloop.

Resources

The following are the resources that cover the topics in detail and will help you further explore the subject in depth.

  1. https://en.wikipedia.org/wiki/Box_blur
  2. https://en.wikipedia.org/wiki/Gaussian_blur
  3. How Blurs & Filters Work — Computerphile

--

--