From 395729aca1e0e31523ba61908039de1dc3736fb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Sat, 24 Feb 2018 20:04:44 +0100 Subject: [PATCH] Simple OO refactor --- imgrate.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/imgrate.py b/imgrate.py index dbb0af5..c7548b6 100755 --- a/imgrate.py +++ b/imgrate.py @@ -4,17 +4,20 @@ import numpy as np from argparse import ArgumentParser -def laplacian_variance(image): - return cv2.Laplacian(image, cv2.CV_64F).var() +class imgrate: + def __init__(self, image=None): + self.image = image + def laplacian_variance(self): + return cv2.Laplacian(self.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]) + def fdibm(self): + F = np.fft.fft2(self.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__': @@ -25,4 +28,4 @@ if __name__ == '__main__': image = cv2.imread(args.images[0]) grayscale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) - print(fdibm(grayscale)) \ No newline at end of file + print(imgrate(grayscale).fdibm()) \ No newline at end of file