Python边缘检测与曲率计算
我知道之前已经发布过边缘检测问题(Java:,独立于语言:),但我想知道如何在python中实现它Python边缘检测与曲率计算,python,image-processing,computer-vision,Python,Image Processing,Computer Vision,我知道之前已经发布过边缘检测问题(Java:,独立于语言:),但我想知道如何在python中实现它 from scipy import ndimage edge_horizont = ndimage.sobel(greyscale, 0) edge_vertical = ndimage.sobel(greyscale, 1) magnitude = np.hypot(edge_horizont, edge_vertical) 我正在做一些简单形状的边缘检测和曲率计算(带有一些噪声的二元形状)。
from scipy import ndimage
edge_horizont = ndimage.sobel(greyscale, 0)
edge_vertical = ndimage.sobel(greyscale, 1)
magnitude = np.hypot(edge_horizont, edge_vertical)
我正在做一些简单形状的边缘检测和曲率计算(带有一些噪声的二元形状)。我知道OpenCV有一些包装,但不确定哪一个更好:pyopencv,pycv,pycvf
由于我基本上只做这两项任务,我也不确定自己实现它是否比使用库更快。我们在积极开发的
scikit图像中有分割和边缘检测算法,您可能会发现这些算法很有用:
使用scikit图像在python中查找轮廓有一种非常简单的方法。这实际上只是几行代码,如下所示:
from skimage import measure
contours = measure.find_contours(gimg, 0.8)
这将返回等高线的矢量表示形式。在每行的单独数组中。通过计算近似值,也很容易减少直线上的点数。下面是对源代码的较长描述:您可以使用python中的scipy轻松实现边缘检测
from scipy import ndimage
edge_horizont = ndimage.sobel(greyscale, 0)
edge_vertical = ndimage.sobel(greyscale, 1)
magnitude = np.hypot(edge_horizont, edge_vertical)
这里是原始图像和边缘检测后的图像的示例
在scikit图像中,有一系列的边缘检测方法。您可以使用不同的边缘检测器:Canny、Sobel、Laplacian、Scharr、Prewitt、Roberts。您可以通过以下方式完成:
或与:
Canny边缘检测器可能是最常用和最有效的方法,但也是最复杂的方法。有关上述方法之间的差异的更多详细信息,请检查。我建议从他们的网站下载OpenCV——如果您使用他们的指令编译它,您将自动获得python包装器(import cv2
)。此外,看一看关于曲率计算的scipy.ndimage
新闻?边缘检测很酷。你会进行曲率计算吗?@clwen如何定义曲率?如果你给我一张纸或一个例子,我们可以给它一个镜头。如何将创建的边缘覆盖回原始图像
import cv2
from skimage import feature, filters
img = cv2.imread('your_image.jpg', 0)
edges_canny = feature.canny(img) # Canny
edges_sobel = filters.sobel(img) # Sobel
edges_laplace = filters.laplace(img) # Laplacian
edges_scharr = filters.scharr(img) # Scharr
edges_prewitt = filters.prewitt(img) # Prewitt
edges_roberts = filters.roberts(img) # Roberts