Make image ratings properties

This commit is contained in:
Kristóf Tóth 2018-02-24 20:30:02 +01:00
parent 66942b9b4b
commit 7769250b15
1 changed files with 8 additions and 3 deletions

View File

@ -5,16 +5,18 @@ from argparse import ArgumentParser
from functools import wraps
def image_required(fun):
@wraps(fun)
def wrapper(self, *args, **kwargs):
if self.image is None:
raise RuntimeError('Method {}.{} requires an image!'
raise RuntimeError('Property {}.{} requires an image!'
.format(self.__class__.__name__, fun.__name__))
return fun(self, *args, **kwargs)
return wrapper
class imgrate:
def __init__(self, imgfile=None):
self.image = None
@ -24,10 +26,12 @@ class imgrate:
image = cv2.imread(imgfile)
self.image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
@property
@image_required
def laplacian_variance(self):
def laplacian(self):
return cv2.Laplacian(self.image, cv2.CV_64F).var()
@property
@image_required
def fdibm(self):
F = np.fft.fft2(self.image)
@ -38,9 +42,10 @@ class imgrate:
return Th / (F.shape[0] * F.shape[1])
if __name__ == '__main__':
ap = ArgumentParser()
ap.add_argument('images', type=str, nargs='+', help='')
args = ap.parse_args()
print(imgrate(args.images[0]).laplacian_variance())
print(imgrate(args.images[0]).laplacian)