2

I'm look for a way to programatically check whether images are blurry or not and am interested in hearing any options I have to do so. I could use any programming language, though I'm most familiar with PHP and Python.

Thanks in advance for any ideas you have.

user994585
  • 661
  • 3
  • 13
  • 28
  • 1
    possible duplicate of [Is there a way to detect if an image is blurry?](http://stackoverflow.com/questions/7765810/is-there-a-way-to-detect-if-an-image-is-blurry) – Roger Rowland Mar 02 '15 at 14:41

1 Answers1

6

There's a lot of advice on here about computing Laplacian of Gaussians and theoretical stuff, but I sense you want something practical and easy, so I would suggest you use ImageMagick like this to compute the Laplacian at the command line. It is installed on most Linux distros and available for Windows and OS X.

Here is a sharp image:

enter image description here

and I compute its Lapalacian like this at the command line

convert face1.jpg colorspace gray -define convolve:scale='!' -bias 50% \
   -morphology Convolve Laplacian:0   laplacian.png

enter image description here

and get the statistics like this, looking at the min/max and the standard deviation:

identify -verbose laplacian.png | grep -E "min|max|deviation"

  min: 44 (0.172549)
  max: 200 (0.784314)
  standard deviation: 4.52133 (0.0177307)

Now I do the same for a blurry version

enter image description here

and I get this:

identify -verbose laplacian.png | grep -E "min|max|deviation"
min: 118 (0.462745)
max: 135 (0.529412)
standard deviation: 0.835725 (0.00327735)

You can either shell out from PHP and use the commands I am giving, or use the PHP bindings for ImageMagick.

If you don't want the image output and are just interested in the statistics, you can avoid creating an intermediate file like this:

convert blur.jpg -colorspace gray       \
  -define convolve:scale='!' -bias 50%  \
  -morphology Convolve Laplacian:0 -verbose info: | grep -Ei "min|max|deviation"
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • i know this answer is quite ancient, but I would like to ask, which value should I look at (min, max or sd?), in order to identify blurry images? I applied this command to various blurry images, and I found the results vary. Some blurry images have a max value of around 129 while the others have a max value of around 200. Same for normal images. I cannot identify the images based on the max value. Example: normal image (min: 51, max: 205), blur image #1 (min: 125, max: 129), blur image #2 (min: 55, max: 201)... – Raptor Jan 10 '22 at 04:12
  • @Raptor Things have moved on in 7 years, and there are also new, highly knowledgeable folk on Stack Overflow. I would encourage you to ask a new question, with representatives images, since questions are free, and get the attention of new members rather than tagging onto this old question where you'll get a limited audience. – Mark Setchell Jan 10 '22 at 07:22
  • 1
    Sure I will. Thanks. – Raptor Jan 10 '22 at 07:23