python - 具有 Python 特定过滤器的 OpenCV 不一样

标签 python opencv

我正在尝试使用 OpenCV 在 Python 中制作一个 Kirsch 过滤器。我正在尝试在 this article 之后这样做.

问题是它给我的结果与 Matlab 的结果完全不同。

预期输出

Blood vessel extraction from eye

Python 和 OpenCV 给我一个全黑的图像。

我哪里做错了?

这是我写的代码:

import cv2
import numpy as np
np.set_printoptions(threshold=np.nan)
resim = cv2.imread('filter.jpg')
resim = cv2.cvtColor(resim, cv2.COLOR_RGB2GRAY)
h1 = np.array([[5, -3, -3], [-5, 0, -3], [5, -3, -3]], dtype=np.float32)/ 15
h2 = np.array([[-3, -3, 5], [-3, 0, 5], [-3, -3, 5]], dtype=np.float32) / 15
h3 = np.array([[-3, -3, -3], [5, 0, -3], [5, 5, -3]], dtype=np.float32) / 15
h4 = np.array([[-3, 5, 5], [-3, 0, 5], [-3, -3, -3]], dtype=np.float32) / 15
h5 = np.array([[-3, -3, -3], [-3, 0, -3], [5, 5, 5]], dtype=np.float32) / 15
h6 = np.array([[5, 5, 5], [-3, 0, -3], [-3, -3, -3]], dtype=np.float32) / 15
h7 = np.array([[-3, -3, -3], [-3, 0, 5], [-3, 5, 5]], dtype=np.float32) / 15
h8 = np.array([[5, 5, -3], [5, 0, -3], [-3, -3, -3]], dtype=np.float32) / 15
print(h1)
new_img1 = cv2.filter2D(resim, -1, h1)
new_img2 = cv2.filter2D(resim, -1, h2)
new_img3 = cv2.filter2D(resim, -1, h3)
new_img4 = cv2.filter2D(resim, -1, h4)
new_img5 = cv2.filter2D(resim, -1, h5)
new_img6 = cv2.filter2D(resim, -1, h6
new_img7 = cv2.filter2D(resim, -1, h7)
new_img8 = cv2.filter2D(resim, -1, h8)
cv2.imshow('color_image', new_img1)
cv2.waitKey(0)
cv2.destroyAllWindows()

最佳答案

第 6 行有一个错误,您的值是 -5,而不是 5。

h1 = np.array([[5, -3, -3], [5, 0, -3], [5, -3, -3]], dtype=np.float32)/ 15

关于python - 具有 Python 特定过滤器的 OpenCV 不一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20169137/

相关文章:

python - 如何立即更新 Kivy 中的小部件?

python - TensorFlow 2.0 GradientTape 返回 None 作为手动模型的梯度

c++ - 如何在 OpenCV 中将图像读取为 double?

python - 在二值图像上查找厚物体

python - OpenCV 特征匹配图像中的多个相似对象

python - 名称 'net_input' 未定义,即使它在全局中

python - Pyqtgraph绘图小部件: cannot change font weight of axis ticks to BOLD

opencv - opencv编程中的函数

android - Laplacian OpenCV Android无法正常工作

python - 在每行开头添加前缀不起作用