Why you should blur an image before processing it using OpenCV and Python

If you start playing around with computer vision there are a couple of surprises waiting. One of them, for me at least, was how bad computers are at finding shapes in noisy images and, in contrast to that, how good the human brain is at this task.

For example, take this simple image:

shape

original shape image

 

We want to first run canny edge detection, so we first convert it into gray scale.

shape_grayscale

gray scale shape image

 

Now, we add some noise to it.

shape_noise

noisy, non blurred shape image

 

You can still make out the shape just fine but when you now try to detect edges with the canny edge detection in opencv this happens:

shape_edges_noise

canny edge detection

 

Now, when we try to find contours we get this:

shape_outuput_noise

contour detection

 

But, if we first blur the image, then use canny edge and then find contours we get this:

shape_blurred

blurred image

shape_edges

canny edge detection

shape_outuput

contour is found

As you can see it is not perfect but almost perfect and certainly better than without the blurring of the image.

Example python code:

 

 

This entry was posted in computer vision, Linux, python. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*