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:


original shape image


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


gray scale shape image


Now, we add some noise to it.


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:


canny edge detection


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


contour detection


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


blurred image


canny edge detection


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 *