Blur Detection using the variance of the Laplacian method

In the previous blog, we discussed how to detect low contrast images using the scikit image library. Similar to low contrast images, the blurred images also don’t provide any additional information for our task. So, it’s better to discard these blurred images before doing any task such as in computer vision or any other. Blur detection is an active research topic and several algorithms have been proposed not only for detecting blur but also to deblur the image. So, in this blog, we will discuss one such simple yet effective method for detecting blur. So, let’s get started.

As we all know that the blurry image doesn’t have well-defined edges. So, if you calculate the Laplacian of this image, you will get more or less the same response everywhere. In other words, the variance of this Laplacian image will be less. Now the main question is how much less is less. So you choose a threshold and if the variance is less than this threshold, the image is blurred otherwise not.

So, for a blurred image, the variance of the laplacian will be less as compared to the sharp image. That is why this method is known as the variance of the Laplacian.

Now, the main thing is to set a threshold that decides if an image is blurred or not. Actually, this is a tricky part and this all depends upon your application. So you may need to try out different threshold values and pick out the one that works well for your application. I hope you understood this. Now, let’s see how to implement this using OpenCV-Python.

Steps

  • Load the image
  • Convert this to greyscale
  • Calculate the laplacian of this image and find the variance
  • If variance < threshold then blurred, otherwise not

So this is how this method works. As we already know that the laplacian is very sensitive to noise so this may not give good results. Also setting a good threshold value is also a tricky part. This method is fast and easy to implement but is not guaranteed to work for almost every case. As I already told you that this is an active research area so in the next blog, we will use the Fourier transform and see how it goes. That’s all for this blog. Hope you enjoy reading.

If you have any doubts/suggestions please feel free to ask and I will do my best to help or improve myself. Goodbye until next time.

Leave a Reply