diff --git a/imgrate.py b/imgrate.py index cc9b923..f36fc8d 100755 --- a/imgrate.py +++ b/imgrate.py @@ -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)