Convolution is one of those simple concepts that is really easy to complicate, so I’m going to try to keep it as simple as it should be. Basically, convolution is the multiplication of one thing by another. Usually, it’s the multiplication of a big thing by a small thing, and, I can tell by the blank stares that I have already complicated things! Maybe I should give an example.
First, here is a small thing, let’s call it the Kernel:
Now here is a big thing, let’s call it the Big Thing:
Let’s say each number in the big thing represents an individual pixel value. The way it works is, you take each number of the kernel and you multiply each of the first three numbers of the big thing, then you add results together:
But the result is now too big! So, we have to adjust it based on the ‘weight’ of the kernel. The weight of the kernel is given by adding all the kernel values together i.e. 1 + 2 + 1 = 4. Now, we adjust the result like this 10 ÷ 4 = 2.5 (to keep things clean we will simply drop the ‘.5’). Now we replace the second number of the big thing with the new result:
You will notice that the number that gets replaced in the big thing is always in the centre position of the kernel (small thing). Now you slide the kernel to the right by one position and do it again:
And you keep going until you have replaced all the numbers with new ones:
Now, the smarty pants among you probably noticed that the first and last numbers did not change. That is because I am lazy, and I didn’t feel like chopping up my kernel to handle the ‘limit conditions’. But just to prove I know how to do it:
The faded kernel numbers are not used because they don’t have a number under them when handling the ‘limit conditions’. I just kept them so the kernel is easier to recognize. When, doing a convolution in image processing, the edge pixels are sometimes not processed because they have to get handled differently (as you have just seen) and that usually takes extra processing power.
By now, some of you are probably wondering ‘OK, it’s cool and everything but what do you do with it?’ That, I will leave for next time.
About this article: Bob’s Imaging Fundamentals is an article series based on the work of Bob Howison. Originally titled Bob’s Brain Snacks, these articles were intended to help employees and partners get up to speed with the fundamental concepts of image processing. They became such a popular reference that we’ve decided to bring them to the Possibility Hub. As technology goes further, faster, and new industries discover the power of digital imaging, it’s important to remember the basics.
Bob’s Brain Snacks are recommended for anyone interested in learning about imaging technology. Sharpen your mind and try one!