Skip to content

This blur detection python script uses the Fast Fourier Transform method to detect potential blur in images

Notifications You must be signed in to change notification settings

christine-peng/Fast-Fourier-Transform-for-Blur-Detection-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Fast-Fourier-Transform-for-Blur-Detection-

Introduction

The Fourier Transform is an image processing tool which is used to decompose an image into its sine and cosine components. The output of the transformation convert an incoming signal from time domain to a Fourier, or frequency domain. In the simplest terms, a fourier transform breaks down an incoming signal into its building blocks. It is useful in a wide range of applications, such as image analysis, image filtering, image reconstruction and image compression. For digital images, the 2D Discrete Fourier Transform (DTF) is used to find the frequency domain. A fast algorithm called Fast Fourier Transform (FFT) is used for the calculation of DTF.

In terms of computer vision, FFT is an image processing tool that represents an image in two domains:

  1. Fourier (frequency) domain
  2. Spatial domain

Therefore, the FFT represents the image in both real and imaginary components. When a FFT is applied to an image, it converts an input image from a spatial domain to frequency domain, which separates an image’s high and low frequencies. image In the FFT transform of an image, low frequencies are situated towards the center of the image and high frequencies are scattered around, as shown above. A Boolean mask can then be created to represent the center as zeros and the rest of the area as ones. When the mask is applied to the original image, the resultant image would only have high frequencies. Low frequencies correspond to edges in a spatial domain. Essentially, an image is a considered a signal sampled in two directions, so taking the Fourier transform in both X and Y directions results in the frequency representation of the image.

Once the FFT is visualized, an FFT shift can be made to remove low frequencies. This can be done by applying the inverse shift to put the zero frequency component in the top-left of the image, and apply the inverse FFT to enable edge detection functionality.

In order to determine if an image is blurry, the magnitude spectrum of an image is derived again from the reconstructed image after the zero frequency component have been zeroed out. The mean of the magnitude representation is then calcualated, returning a boolean indicating whether the input image is blurry or not.

How to use

There are two Python files: fourier_blur.py Implements fast fourier transform (FFT) blur detector algorithm
blur_detector_image.py: Python driver script that loads an input image from disk and then applies FFT blur detection to it.

Place images in one project folder, and run command prompt to access project folder:

imagepath python blur_detector_image.py --i images  

To change threshold of image output:

imagepath python blur_detector_image.py --i images --thresh 15

Results Analysis

Screenshot of images used (left) and blur results (right). image Similar to the Laplacian method, blur detection using the Fast Fourier Transform is dependant on the pre-defined threshold, which will range depending on type of images taken. For example, the image below is has a threshold of "30.2", which is too blurry for analysis, so a threshold of "32" was set to manually set it to blurry. image A threshold of "32" accurately represents blur in the photo above, yet the same blur threshold doesn't work for all the images, as demonstrated in the four pictures below. image image image image

Limitations

Similar to the Laplacian method, the FFT also requires manual tuning to define the blur threshold. The advantage of a pre-defined threshold is that this method can be custom tailored to different types of images, but it's disadvantage lays in the fact that each set of images must be of similar location, and with similar attributes. Variations in characteristics of images, such as snow (as shown below), is mistaken as blurry due to low levels of edge variation, would not work with the FFT method unless they were isolated from other images, with a new threshold manually set. image Results also seemed inconsistent for images with a clear object of interest and blurred background, as shown in examples below. image Results were also inconsistent for images with reflections, as shown in examples below. image image

Conclusion

While the Fast Fourier Transform method can be potentially used to detect blur in UAV images, it would have to be manually tuned to a threshold appropriate for each set of images. Environmental factors such as snow and rain may likely result in mixed results. Reflections and background blur may also result in mixed results. The FFT method is best used for images taken within a similar setting, set in a controlled environment. Large variations in imagery changes will likely produce mixed results.

About

This blur detection python script uses the Fast Fourier Transform method to detect potential blur in images

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages