Detecting how blurred an image is

允我心安 提交于 2019-12-04 19:23:23
ErmIg

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

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

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