From 50d022380bddfdcc6ddeab9c389f922b8613d808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Mon, 1 Jan 2018 21:49:00 +0100 Subject: [PATCH] implemented Frequency Domain Image Blur Measure (review required) --- imgrate.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/imgrate.py b/imgrate.py index ba68dd5..dbb0af5 100755 --- a/imgrate.py +++ b/imgrate.py @@ -1,11 +1,20 @@ #!/usr/bin/env python3 import cv2 +import numpy as np from argparse import ArgumentParser def laplacian_variance(image): - grayscale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) - return cv2.Laplacian(grayscale, cv2.CV_64F).var() + return cv2.Laplacian(image, cv2.CV_64F).var() + + +def fdibm(image): + F = np.fft.fft2(image) + Fcentered = np.fft.fftshift(F) + Fabs = np.abs(Fcentered) + Fmax = Fabs.max() + Th = np.count_nonzero(Fabs > Fmax/1000) + return Th / (F.shape[0] * F.shape[1]) if __name__ == '__main__': @@ -14,5 +23,6 @@ if __name__ == '__main__': args = ap.parse_args() image = cv2.imread(args.images[0]) + grayscale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) - print(laplacian_variance(image)) \ No newline at end of file + print(fdibm(grayscale)) \ No newline at end of file