Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detection of Blur in Images/Video sequences

I had asked this on photo stackexchange but thought it might be relevant here as well, since I want to implement this programatically in my implementation.

I am trying to implement a blur detection algorithm for my imaging pipeline. The blur that I want to detect is both -

1) Camera Shake: Pictures captured using hand which moves/shakes when shutter speed is less.

2) Lens focussing errors - (Depth of Field) issues, like focussing on a incorrect object causing some blur.

3) Motion blur: Fast moving objects in the scene, captured using a not high enough shutter speed. E.g. A moving car a night might show a trail of its headlight/tail light in the image as a blur.

How can one detect this blur and quantify it in some way to make some decision based on that computed 'blur metric'?

What is the theory behind blur detection?

I am looking of good reading material using which I can implement some algorithm for this in C/Matlab.

thank you.

-AD.

like image 403
goldenmean Avatar asked Mar 03 '11 11:03

goldenmean


People also ask

Is there a way to detect if an image is blurry?

If you have any background in signal processing, the first method to consider would be computing the Fast Fourier Transform of the image and then examining the distribution of low and high frequencies — if there are a low amount of high frequencies, then the image can be considered blurry.

How does Python detect blurry images?

You can try to define a threshold as float, so for every result falling under the threshold == blurry. But if the pixel images shows very high every time, even if not blurry, you could check for another value that is very high. Another way might be to detect focus of the picture.

What is FFT in image processing?

The Fast Fourier Transform (FFT) is commonly used to transform an image between the spatial and frequency domain. Unlike other domains such as Hough and Radon, the FFT method preserves all original data. Plus, FFT fully transforms images into the frequency domain, unlike time-frequency or wavelet transforms.

How can you tell motion blur?

Thus, given an image, we can determine whether it is blurred by motion, by detecting areas where there is smoothness in one main direction and more significant difference of values in the vertical direction. If we found that motion blur, we can compute its direction of motion relatively to the camera.


3 Answers

Motion blur and camera shake are kind of the same thing when you think about the cause: relative motion of the camera and the object. You mention slow shutter speed -- it is a culprit in both cases.

Focus misses are subjective as they depend on the intent on the photographer. Without knowing what the photographer wanted to focus on, it's impossible to achieve this. And even if you do know what you wanted to focus on, it still wouldn't be trivial.

With that dose of realism aside, let me reassure you that blur detection is actually a very active research field, and there are already a few metrics that you can try out on your images. Here are some that I've used recently:

  • Edge width. Basically, perform edge detection on your image (using Canny or otherwise) and then measure the width of the edges. Blurry images will have wider edges that are more spread out. Sharper images will have thinner edges. Google for "A no-reference perceptual blur metric" by Marziliano -- it's a famous paper that describes this approach well enough for a full implementation. If you're dealing with motion blur, then the edges will be blurred (wide) in the direction of the motion.
  • Presence of fine detail. Have a look at my answer to this question (the edited part).
  • Frequency domain approaches. Taking the histogram of the DCT coefficients of the image (assuming you're working with JPEG) would give you an idea of how much fine detail the image has. This is how you grab the DCT coefficients from a JPEG file directly. If the count for the non-DC terms is low, it is likely that the image is blurry. This is the simplest way -- there are more sophisticated approaches in the frequency domain.

There are more, but I feel that that should be enough to get you started. If you require further info on either of those points, fire up Google Scholar and look around. In particular, check out the references of Marziliano's paper to get an idea about what has been tried in the past.

like image 190
mpenkov Avatar answered Nov 10 '22 02:11

mpenkov


There is a great paper called : "analysis of focus measure operators for shape-from-focus" (https://www.researchgate.net/publication/234073157_Analysis_of_focus_measure_operators_in_shape-from-focus) , which does a comparison about 30 different techniques.

Out of all the different techniques, the "Laplacian" based methods seem to have the best performance. Most image processing programs like : MATLAB or OPENCV have already implemented this method . Below is an example using OpenCV : http://www.pyimagesearch.com/2015/09/07/blur-detection-with-opencv/

like image 41
rugby2312 Avatar answered Nov 10 '22 02:11

rugby2312


One important point to note here is that an image can have some blurry areas and some sharp areas. For example, if an image contains portrait photography, the image in the foreground is sharp whereas the background is blurry. In sports photography, the object in focus is sharp and the background usually has motion blur. One way to detect such a spatially varying blur in an image is to run a frequency domain analysis at every location in the image. One of the papers which addresses this topic is "Spatially-Varying Blur Detection Based on Multiscale Fused and Sorted Transform Coefficients of Gradient Magnitudes" (cvpr2017).

the authors look at multi resolution DCT coefficients at every pixel. These DCT coefficients are divided into low, medium, and high frequency bands, out of which only the high frequency coefficients are selected. The DCT coefficients are then fused together and sorted to form the multiscale-fused and sorted high-frequency transform coefficients A subset of these coefficients are selected. the number of selected coefficients is a tunable parameter which is application specific. The selected subset of coefficients are then sent through a max pooling block to retain the highest activation within all the scales. This gives the blur map as the output, which is then sent through a post processing step to refine the map. This blur map can be used to quantify the sharpness in various regions of the image. In order to get a single global metric to quantify the bluriness of the entire image, the mean of this blur map or the histogram of this blur map can be used

Here are some examples results on how the algorithm performs:

enter image description here

The sharp regions in the image have a high intensity in the blur_map, whereas blurry regions have a low intensity.

The github link to the project is: https://github.com/Utkarsh-Deshmukh/Spatially-Varying-Blur-Detection-python

The python implementation of this algorithm can be found on pypi which can easily be installed as shown below:

pip install blur_detector

A sample code snippet to generate the blur map is as follows:

import blur_detector
import cv2
if __name__ == '__main__':
    img = cv2.imread('image_name', 0)
    blur_map = blur_detector.detectBlur(img, downsampling_factor=4, num_scales=4, scale_start=2, num_iterations_RF_filter=3)

    cv2.imshow('ori_img', img)
    cv2.imshow('blur_map', blur_map)
    cv2.waitKey(0)
  • For detecting blurry images, you can tweak the approach and add "Region of Interest estimation". In this github link: https://github.com/Utkarsh-Deshmukh/Blurry-Image-Detector , I have used local entropy filters to estimate a region of interest. In this ROI, I then use DCT coefficients as feature extractors and train a simple multi-layer perceptron. On testing this approach on 20000 images in the "BSD-B" dataset (http://cg.postech.ac.kr/research/realblur/) I got an average accuracy of 94%
like image 38
Utkarsh Deshmukh Avatar answered Nov 10 '22 02:11

Utkarsh Deshmukh