Simple OO refactor
This commit is contained in:
parent
50d022380b
commit
395729aca1
23
imgrate.py
23
imgrate.py
@ -4,17 +4,20 @@ import numpy as np
|
|||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
|
|
||||||
def laplacian_variance(image):
|
class imgrate:
|
||||||
return cv2.Laplacian(image, cv2.CV_64F).var()
|
def __init__(self, image=None):
|
||||||
|
self.image = image
|
||||||
|
|
||||||
|
def laplacian_variance(self):
|
||||||
|
return cv2.Laplacian(self.image, cv2.CV_64F).var()
|
||||||
|
|
||||||
def fdibm(image):
|
def fdibm(self):
|
||||||
F = np.fft.fft2(image)
|
F = np.fft.fft2(self.image)
|
||||||
Fcentered = np.fft.fftshift(F)
|
Fcentered = np.fft.fftshift(F)
|
||||||
Fabs = np.abs(Fcentered)
|
Fabs = np.abs(Fcentered)
|
||||||
Fmax = Fabs.max()
|
Fmax = Fabs.max()
|
||||||
Th = np.count_nonzero(Fabs > Fmax/1000)
|
Th = np.count_nonzero(Fabs > Fmax/1000)
|
||||||
return Th / (F.shape[0] * F.shape[1])
|
return Th / (F.shape[0] * F.shape[1])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -25,4 +28,4 @@ if __name__ == '__main__':
|
|||||||
image = cv2.imread(args.images[0])
|
image = cv2.imread(args.images[0])
|
||||||
grayscale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
grayscale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
||||||
|
|
||||||
print(fdibm(grayscale))
|
print(imgrate(grayscale).fdibm())
|
Loading…
Reference in New Issue
Block a user