Simple Convolution-Based Image Filters


Section of original image on left, blurred on right

Overview

I’ve been interested in signal and image processing for a while, so I thought it would be a fun and interesting project to try and implement some basic image processing features to learn about how they work.

I followed along with this video, (which is part of an excellent series on image processing and computer vision), and implemented the convolution-based image filters both for black-and-white images as well as color images.

It was a fun and insight-building look into the world of image processing, a topic that, along with graphics as a whole, I am looking forward to studying in depth.

Box Blur

The simplest convolution filter to implement is box blur, which makes every pixel in the output an average of all of the pixels in a corresponding area of the input.

The box blur kernel can be represented as a 3×3 matrix with all values set to 1/9

The image on the right has been box-blurred. This is visible in the less defined edges as opposed to the original

Sharpening

Sharpening is a slightly more complicated filter to implement, but it can still be done with a simple convolution

The sharpening kernel seeks to increase the contrast between pixels, so it takes the form of the 3×3 matrix {[0 -1 0] [-1 5 -1] [0 -1 0]}. This will negate the influence of nearby pixels while increasing the intensity of individual pixels.

The image on the left is the original, while the one on the right has been sharpened.

It is a little hard to see the difference, but notice the slightly sharper edges and the introduction of noise at the edges