Image convolution examples

A convolution is very useful for signal processing in general. There is a lot of complex mathematical theory available for convolutions. For digital image processing, you don’t have to understand all of that. You can use a simple matrix as an image convolution kernel and do some interesting things!

Simple box blur

Here’s a first and simplest. This convolution kernel has an averaging effect. So you end up with a slight blur. The image convolution kernel is:

The convolution kernel for a simple blur

Note that the sum of all elements of this matrix is 1.0. This is important. If the sum is not exactly one, the resultant image will be brighter or darker.

Here’s a blur that I got on an image:

After a simple blur done with a convolution

A simple blur done with convolutions

Gaussian blur

Gaussian blur has certain mathematical properties that makes it important for computer vision. And you can approximate it with an image convolution. The image convolution kernel for a Gaussian blur is:

Here’s a result that I got:

Result of gaussian blur with a convolution

Line detection with image convolutions

With image convolutions, you can easily detect lines. Here are four convolutions to detect horizontal, vertical and lines at 45 degrees:

Convolution kernels for line detectionI looked for horizontal lines on the house image. The result I got for this image convolution was:

Detecting horizontal lines with a convolution

Edge detection

The above kernels are in a way edge detectors. Only thing is that they have separate components for horizontal and vertical lines. A way to “combine” the results is to merge the convolution kernels. The new image convolution kernel looks like this:

The edge detection convolution kernel

Below result I got with edge detection:

Edge detection with convolutions

The Sobel Edge Operator

The above operators are very prone to noise. The Sobel edge operators have a smoothing effect, so they’re less affected to noise. Again, there’s a horizontal component and a vertical component.

The sobel operator's convolution kernel

On applying this image convolution, the result was:

Result of the horizontal sobel operator

The laplacian operator

The laplacian is the second derivative of the image. It is extremely sensitive to noise, so it isn’t used as much as other operators. Unless, of course you have specific requirements.

The kernel for the laplacian operator

Here’s the result with the convolution kernel without diagonals:

The result of convolution with with the laplacian operator

The Laplacian of Gaussian

The laplacian alone has the disadvantage of being extremely sensitive to noise. So, smoothing the image before a laplacian improves the results we get. This is done with a 5×5 image convolution kernel.

The kernel for the laplacial of gaussian operation

The result on applying this image convolution was:

The result of applying the laplacian of gaussian operator

Summary

You got to know about some important operations that can be approximated using an image convolution. You learned the exact convolution kernels used and also saw an example of how each operator modifies an image. I hope this helped!

Issues? Suggestions? Visit the Github issue tracker for AI Shack

Back to top

4 Comments

  1. shivda
    Posted August 17, 2010 at 1:00 am | Permalink

    Dude, nice job summarizing it. My whole PS1 project was based on this.MATLAB has a help page thats quite gud. It is filled with examples and images.
    You dont hav 2 worry abt the *convoluting* matrices in MATLAB. Just type in the name of the convolution and u’ll get the edges. Convolutions with matrices of our choice is also possible.
    Cheers !!

    • Posted August 17, 2010 at 1:13 am | Permalink

      :D That’s exactly what makes Matlab easy to use.. lots of “named constants” that do a lot of work, with minimal effort!

  2. mik
    Posted August 21, 2010 at 10:16 pm | Permalink

    the combined edge kernel and the laplacian with diagonals are the same kernels, however, the pictures are a little different. do you know why?

  3. Praveen
    Posted March 23, 2011 at 11:55 am | Permalink

    Mik,
    I think the images are formed by differnt kernel operations. One with and other without diagonals.

2 Trackbacks

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>