MATLAB 的 Canny 滤波器的 Python 实现

标签 python matlab opencv image-processing scikit-image

在 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/

相关文章:

c++ - 将 nvcc 与 CUDA 6 和 VS 2012 Express 结合使用

python - 将不同的人脸检测器与 dlib 的地标检测器一起使用

python - 有没有一种简单的方法可以在 Python 中逐表将数据库数据从 SQLite 迁移到 Postgres?

python - 一个或多个输入行的 numpy.loadtxt

image - MATLAB 中的涟漪效应

python - 了解 numpy.random.lognormal

c++ - 连接 OpenCV 时对 SGILL 进行编程

python - Python OpenCV 和 MATLAB 之间的不同颜色结果

python - 如何使用 isalpha() 和 isspace()

python - 如何将异常发送到 django 项目的 Sentry