-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3441e93
commit c81ca9f
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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() | ||