Detecting how blurred an image is

烂漫一生 提交于 2019-12-06 13:53:45

问题


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"?


回答1:


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).



回答2:


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



来源:https://stackoverflow.com/questions/19443908/detecting-how-blurred-an-image-is

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!