Image Processing – Convolution

In this post I discuss convolution in image processing and provide a basic overview of the algorithm for actually doing convolution.


In a previous post we discussed matrices and kernels. Both of these topics lay the groundwork for digital image processing, and most image processing involves some sort of convolution, which will be the topic of today’s post.

What is convolution?

Convolution has many different meanings. For example, the general definition of convolution is “a coil or twist, especially one of many.”, in mathematical terms, it refers to the result of two mathematical functions, which produces a third function. This definition is much more similar to the image processing definition of convolution. Convolution is where, given a kernel, multiplied against an array of pixels, you get a result; it’s a little more complex than that, but not too much more. Normally, the way this works in practice is you have an array of pixels converted to a grayscaled image, and a kernel of some sort which is multiplied by the grayscaled image. This doesn’t mean the image is always a grayscaled image, only that it is common for this to be the case (especially for some types of edge detection).

Convolution as an Algorithm

Wikipedia happens to have a really great explanation of convolution via a sudo-code algorithm, which I’ll post here because it saves me time, and you can find a link to this here, which is as follows:

for each image row in input image:
   for each pixel in image row:

      set accumulator to zero

      for each kernel row in kernel:
         for each element in kernel row:

            if element position  corresponding* to pixel position then
               multiply element value  corresponding* to pixel value
               add result to accumulator

      set output image pixel to accumulator

What this is saying, is for every row in an image, you get the next pixel, and for every cell in the kernel, you multiply the current pixel value by the current kernel cell, sum it to a running sum, and when you’ve finished going through the kernel, you set the current pixel value to the running sum you accumulated whilst applying the kernel to the pixel. Pretty simple, and it makes you look like you’re a well learned computer scientist (even though you can basically learn this on Wikipedia in like 10 minutes…not speaking from experience or anything).


With that, we’ve basically covered convolution. Once we start actually applying image processing algorithms in a real world scenario, we’ll look at how this stuff actually gets implemented in code and we’ll be using convolution quite a bit, but for now I figure it’s good to just discuss and understand the basic idea of each topic. If I got anything wrong, had grammatical errors, etc. feel free to blast me for it so I can fix it, thanks for reading, and I’ll see you in the next post.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: