Image Filters: Gaussian Blur

Convolution

In simple terms, convolution is simply the process of taking a small matrix called the kernel and running it over all the pixels in an image. At every pixel, we’ll perform some math operation involving the values in the convolution matrix and the values of a pixel and its surroundings to determine the value for a pixel in the output image.

Gaussian Distributions

Next, let’s turn to the Gaussian part of the Gaussian blur. Gaussian blur is simply a method of blurring an image through the use of a Gaussian function.

Overview

To start off, we’ll need the Gaussian function in two dimensions:

Implementation

We’re almost ready to start the implementation.

Code

To finish our implementation, we’ll also need to normalize the values in our kernel. Otherwise the image will become darker as the values will sum to slightly less than 1. Finally, we’ll need to make sure that the size of the kernel is odd to ensure that there is an actual center pixel.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store