首页 > 解决方案 > 应用 Canny 边缘检测后如何计算边缘数?

问题描述

我有一张图像,我将feature.canny算法应用于它以获得图像的边缘。

原始图像(左)与边缘检测(右)

现在我想计算图像中的边缘以获得单个数字。

任何人都可以帮忙吗?

这是显示图像的代码:

def canny_detection(image):

    # Convert to grayscale and convert the image to float
    RGB = img_as_float(color.rgb2gray(image))

    # Apply Canny edge detection algorithm
    edge_canny = feature.canny(RGB, 2)

    # Plot results
    plt.figure(figsize=(15,5))
    plt.subplot(121)
    plt.imshow(RGB, cmap=cm.gist_gray)
    plt.title('Original image')
    plt.subplot(122)
    plt.imshow(edge_canny, cmap=cm.gist_gray)
    plt.title('Canny edge map')`

我还有一些应用 Canny 的代码,然后从图像中提取数组,如果这有帮助的话:

def canny_detection(image):

# Convert to grayscale and convert the image to float
RGB = img_as_float(color.rgb2gray(image))

# Apply Canny edge detection algorithm
edge_canny = feature.canny(RGB,3)
#print(edge_canny)
edge_canny = edge_canny.astype(int)
#print(edge_canny)

#Get output array
canny_arr = np.array(edge_canny)

# Flatten output array
canny_flat = canny_arr.flatten()
#print(np.count_nonzero(canny_flat))   #to see if the matrix is all zeros

return canny_flat

所以从带有边缘检测的图像中,我想计算边缘的数量。我不太确定如何做到这一点,所以任何帮助都会很棒!

标签: pythoncountedge-detectioncanny-operator

解决方案


您可以只使用连接组件的数量。

但是任何对边缘数量的测量都会很差,尤其是在纹理图像中,因为边缘检测是一个不适定问题,并且取决于噪声水平和检测器设置,您可以获得相同场景的非常不同的结果。

就个人而言,我永远不会使用这个参数。


推荐阅读