Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting how blurred an image is

I want to detect how blurred an image is, may be It can be called "blur extend". I found a useful paper for this:

http://www.cs.cmu.edu/~htong/pdf/ICME04_tong.pdf

I used OpenCV and implemented all steps from this paper, but the result is not same as result from this paper.

Can someone give me any advise for detecting "blur extend"?

like image 683
pars Avatar asked Nov 18 '25 06:11

pars


2 Answers

You can detect a blurring image with using next algorithm:

  1. Convert the image into gray format.
  2. Calculate the maximal absolute second derivative from the gray image (for every point):

    d[x,y] = max(abs(2*d[x,y] - d[x,y+1] -d[x,y-1]), abs(2*d[x,y] - d[x+1,y] -d[x-1,y]));
    
  3. Calculate the histogram of this estimated image (maximal absolute second derivative).

  4. Find the upper quantile (0,999) of this histogram.

  5. If this value is less than the threshold (about 25% from image dynamic range), then the image is blurred.

  6. If you want to estimate a blur value, perform steps 2-5 for reduced image.

You can write these algorithms on their own or use one from the implementation of Simd Library (disclaimer: I'm the author).

  • Simd::BgrToGray or Simd::BgraToGray (for step 1).
  • Simd::AbsSecondDerivativeHistogram (for steps 2-5).
  • Simd::ReduceGray2x2 (for step 6).
like image 64
ErmIg Avatar answered Nov 21 '25 08:11

ErmIg


The answer of Ermlg looks close to best, but in code way in this way I achieved it.

The score below 100 was giving me somewhat blury images.

# applying fast fourier transform to fin d the blur images , taken threshold to be 100 but it can vary

import cv2

def variance_of_laplacian(frame_path):
    # compute the Laplacian of the image and then return the focus
    # measure, which is simply the variance of the Laplacian
    image = cv2.imread(frame_path)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    return cv2.Laplacian(gray, cv2.CV_64F).var()

Source of method was from adrian rosebrock

like image 42
TheExorcist Avatar answered Nov 21 '25 08:11

TheExorcist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!