这是我的第一个问题,欢迎任何批评。
我一直在尝试使用 Python 和 OpenCV 实现本文第 2.2 节中介绍的锐度估计器,但不是很成功。
首先我加载原始图像:
并使用地标裁剪面部,从而生成此地标裁剪图片
.
然后我运行纸上介绍的自定义拉普拉斯过滤器:
# Custom kernels for laplace filter
kernel1 = np.array([[1, -2, 1]])
kernel2 = np.array([[1],
[-2],
[1]])
# Use custom Laplace filter to obtain contours and edges, the more sharp an
# image is the greater the response from the laplace filter
pass1 = cv2.filter2D(cropped_image, cv2.CV_32F, kernel1)
pass2 = cv2.filter2D(cropped_image, cv2.CV_32F, kernel2)
# Get the magnitude (absolute value) of pass1 and pass2
pass1 = np.absolute(pass1)
pass2 = np.absolute(pass2)
# Sum the response from both filters
lap_sum = cv2.add(pass1, pass2, dtype=cv2.CV_32F)
这就是事情似乎出错的地方,预期的结果看起来像这样:
但我得到了这个:
.
此外,该论文称,最终措施是
“蒙版图像的平均拉普拉斯算子响应”
并且分数应该落在 的区间内[0.0, 1.0]
。然而,为了实现这一点,我只需要平均非零像素并对最终分数进行归一化,即使这样,我也得到了 0.1 的 abismal 分数,我认为对于我在本示例中使用的图片应该更高。
如果你想自己运行它,我已经在 colab 上实现了它,看到代码和图片应该更容易解释我的结果。非常感谢。