Make image ratings properties
This commit is contained in:
parent
66942b9b4b
commit
7769250b15
11
imgrate.py
11
imgrate.py
@ -5,16 +5,18 @@ from argparse import ArgumentParser
|
|||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def image_required(fun):
|
def image_required(fun):
|
||||||
@wraps(fun)
|
@wraps(fun)
|
||||||
def wrapper(self, *args, **kwargs):
|
def wrapper(self, *args, **kwargs):
|
||||||
if self.image is None:
|
if self.image is None:
|
||||||
raise RuntimeError('Method {}.{} requires an image!'
|
raise RuntimeError('Property {}.{} requires an image!'
|
||||||
.format(self.__class__.__name__, fun.__name__))
|
.format(self.__class__.__name__, fun.__name__))
|
||||||
return fun(self, *args, **kwargs)
|
return fun(self, *args, **kwargs)
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class imgrate:
|
class imgrate:
|
||||||
def __init__(self, imgfile=None):
|
def __init__(self, imgfile=None):
|
||||||
self.image = None
|
self.image = None
|
||||||
@ -24,10 +26,12 @@ class imgrate:
|
|||||||
image = cv2.imread(imgfile)
|
image = cv2.imread(imgfile)
|
||||||
self.image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
self.image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
||||||
|
|
||||||
|
@property
|
||||||
@image_required
|
@image_required
|
||||||
def laplacian_variance(self):
|
def laplacian(self):
|
||||||
return cv2.Laplacian(self.image, cv2.CV_64F).var()
|
return cv2.Laplacian(self.image, cv2.CV_64F).var()
|
||||||
|
|
||||||
|
@property
|
||||||
@image_required
|
@image_required
|
||||||
def fdibm(self):
|
def fdibm(self):
|
||||||
F = np.fft.fft2(self.image)
|
F = np.fft.fft2(self.image)
|
||||||
@ -38,9 +42,10 @@ class imgrate:
|
|||||||
return Th / (F.shape[0] * F.shape[1])
|
return Th / (F.shape[0] * F.shape[1])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
ap = ArgumentParser()
|
ap = ArgumentParser()
|
||||||
ap.add_argument('images', type=str, nargs='+', help='')
|
ap.add_argument('images', type=str, nargs='+', help='')
|
||||||
args = ap.parse_args()
|
args = ap.parse_args()
|
||||||
|
|
||||||
print(imgrate(args.images[0]).laplacian_variance())
|
print(imgrate(args.images[0]).laplacian)
|
||||||
|
Loading…
Reference in New Issue
Block a user