python - 应用 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
所以从带有边缘检测的图像中,我想计算边缘的数量。我不太确定如何做到这一点,所以任何帮助都会很棒!
解决方案
您可以只使用连接组件的数量。
但是任何对边缘数量的测量都会很差,尤其是在纹理图像中,因为边缘检测是一个不适定问题,并且取决于噪声水平和检测器设置,您可以获得相同场景的非常不同的结果。
就个人而言,我永远不会使用这个参数。
推荐阅读
- c++ - 包含中的 C++“取消定义”模块关键字
- javascript - 如何解决节点js中的刷新问题
- r - 如何在向量中找到三个最接近(最近)的值?
- css - CSS sticky position handling different title heights
- python - 在 PDF 文件中导出小部件
- javascript - 从字符串序列中获取 n 对
- python - TypeError: only size-1 arrays can be convert to Python scalars this error
- android - 使用 ItemTouchHelper 时如何在 RecyclerView 中取消拖动项目?
- c# - Linq:高性能数据库查询仅查询每个第 n 个元素
- regular-language - 为正则表达式构造 CFG