Loading imgutils/metrics/__init__.py +1 −0 Original line number Diff line number Diff line Loading @@ -5,5 +5,6 @@ Overview: from .aesthetic import * from .ccip import * from .dbaesthetic import * from .laplacian import * from .lpips import * from .psnr_ import * imgutils/metrics/laplacian.py 0 → 100644 +35 −0 Original line number Diff line number Diff line import cv2 import numpy as np from ..data import load_image, ImageTyping __all__ = [ 'laplacian_score' ] def _variance_of_laplacian(d_image: np.ndarray): """ Calculate the variance of Laplacian for a given image. :param d_image: The input image as a numpy array. :type d_image: np.ndarray :return: The variance of Laplacian. :rtype: float """ return cv2.Laplacian(d_image, cv2.CV_64F).var() def laplacian_score(image: ImageTyping) -> float: """ Calculate the Laplacian score for the given image. The Laplacian score is a measure of image bluriness. :param image: The input image. :type image: ImageTyping :return: The Laplacian score. :rtype: float """ v = np.array(load_image(image, force_background='white', mode='L')) return _variance_of_laplacian(v).item() Loading
imgutils/metrics/__init__.py +1 −0 Original line number Diff line number Diff line Loading @@ -5,5 +5,6 @@ Overview: from .aesthetic import * from .ccip import * from .dbaesthetic import * from .laplacian import * from .lpips import * from .psnr_ import *
imgutils/metrics/laplacian.py 0 → 100644 +35 −0 Original line number Diff line number Diff line import cv2 import numpy as np from ..data import load_image, ImageTyping __all__ = [ 'laplacian_score' ] def _variance_of_laplacian(d_image: np.ndarray): """ Calculate the variance of Laplacian for a given image. :param d_image: The input image as a numpy array. :type d_image: np.ndarray :return: The variance of Laplacian. :rtype: float """ return cv2.Laplacian(d_image, cv2.CV_64F).var() def laplacian_score(image: ImageTyping) -> float: """ Calculate the Laplacian score for the given image. The Laplacian score is a measure of image bluriness. :param image: The input image. :type image: ImageTyping :return: The Laplacian score. :rtype: float """ v = np.array(load_image(image, force_background='white', mode='L')) return _variance_of_laplacian(v).item()