【发布时间】:2019-01-23 12:27:56
【问题描述】:
我有一张图像,我对其应用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
所以从带有边缘检测的图像中,我想计算边缘的数量。我不太确定该怎么做,所以任何帮助都会很棒!
【问题讨论】:
-
有兴趣看看是否找到了解决方案?
-
@user14578710 这是不久前的事了,但这个stackoverflow.com/questions/54889712/gradient-of-edges-python 对弄清楚如何做很有用
标签: python count edge-detection canny-operator