Simple OO refactor

This commit is contained in:
Kristóf Tóth 2018-02-24 20:04:44 +01:00
parent 50d022380b
commit 395729aca1
1 changed files with 13 additions and 10 deletions

View File

@ -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))
print(imgrate(grayscale).fdibm())