我有以下代码来检测输入图像是否模糊。
from imutils import paths
import argparse
import cv2
import os
def variance_of_laplacian(image):
# compute the Laplacian of the image and then return the focus
# measure, which is simply the variance of the Laplacian
return cv2.Laplacian(image, cv2.CV_64F).var()
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--images", required=True,
help="path to input directory of images")
ap.add_argument("-t", "--threshold", type=float, default=100.0,
help="focus measures that fall below this value will be considered 'blurry'")
args = vars(ap.parse_args())
# loop over the input images
for imagePath in paths.list_images(args["images"]):
# load the image, convert it to grayscale, and compute the
# focus measure of the image using the Variance of Laplacian
# method
image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
fm = variance_of_laplacian(gray)
text = "Not Blurry"
# if the focus measure is less than the supplied threshold,
# then the image should be considered "blurry"
if fm < args["threshold"]:
text = "Blurry"要使用该脚本,我运行以下命令:
python detect_blur.py --images images其中images是包含一系列照片的文件夹名称。
然而,结果是相当不准确的(假设拉普拉斯数值< 100被认为是模糊的):
它检测到这张照片是模糊的(正确,拉普拉斯值= 1.26):

但它检测到这张照片也是模糊的(不正确,拉普拉斯值= 62.9):

如何让代码更准确?我想特别检测高斯模糊,如何更改代码?
发布于 2020-05-22 15:51:35
对于第二张图像,除了底部之外,客观上它是模糊的。
因此,如果您将每个输入图像细分为25个块(即5x5网格)并计算每个块的焦点值,则可能会获得更好的结果。然后,您可以使用例如焦点的最大值(或者其他度量,如mean或median,如果这对您更有效?)作为完整图像的焦点值。
发布于 2022-01-21 01:50:52
最后,我自己设计了一个库,通过检查拉普拉斯值来检查模糊图像。
要安装库,请使用pip install imgtoolkit。然后,使用这个简单的脚本,我们可以找到模糊的图像并将它们移动到一个单独的文件夹中。
from imgtoolkit import tools
if __name__ == '__main__':
# Find blur photos
tools.find_blur()Github的源代码可以在here上找到。
https://stackoverflow.com/questions/61950113
复制相似问题