Quantifying image blurriness using cv2.Laplacian


Designing personalized photo books is a great activity for dark winter evenings. One change introduced by digital photography is the number of snaps taken in every photo opportunity, and in total. Because sharing photos takes likewise less effort than in paper photo time, the photo book project could easily start with folders containing thousands of photos. However, not all the snaps are worth keeping.

As in information era in general, some smart person usually has already found a solution for the problem. A great post by Adrian Rosebrock describes how to quantify the blurriness in images using variation of the Laplacian. The continuous Laplacian is a well-known second-order differential operator and the discrete version of the operator (images are sets of pixels) has an application in edge detection. The main idea is that a sharp image should have a fair number of edges while unfocused image is more smooth.

I made two minor changes in the script provided by Rosebrock: (1) I resized all images to approximately same size (height 500 px) before calculating the variance and (2) I moved the images in three different folders representing low, medium, and high quality categories.

I had originally collected 1518 images for my next photo book project, but cv2.Laplacian reduced the number to 690 potential high quality images. I am additionally going to be spared from going through 71 clearly misfocused takes. I present below as an example one equal size crop from each category.

Three levels of blurriness


See also