在 MATLAB 中调用以下函数将 Canny 滤波器应用于图像:
edges = edge(image, 'Canny');
我知道有两个 Python 函数实现了 Canny 过滤器:
import cv2
edges = cv2.Canny(image)
和
from skimage import feature
edges = feature.canny(image)
但是,这些 Python 函数都不能像 MATLAB 那样计算过滤器的高阈值和低阈值。根据this neuroimaging paper ,
. . . the default MATLAB algorithm [generates] the two thresholds such that the high threshold is calculated to be the lowest value at which no more than 30% of the pixels are detected as edges, and the low threshold is defined as 40% of the high threshold.
是否有可以执行此操作的 Python 实现?
最佳答案
您应该首先将 Canny 参数传递给 canny()
,然后在您的 Python 代码中运行它
im: 图片名称
下限:
上限:
import cv2
import matplotlib.pyplot as plt
img = cv2.imread('lena.png')
edges = cv2.Canny(img,....,....,L2gradient=False/True)
plt.imshow(edges,cmap='gray')
plt.show()
关于MATLAB 的 Canny 滤波器的 Python 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30282909/