[英]Convert Canny edge detection into np.array
我編寫了一個函數,希望使用Canny算法檢測圖像的邊緣。 然后,我想提取此圖像的2d數組,然后將其展平為1d數組。
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).astype(int)
#Get output array
canny_arr = np.array(edge_canny)
# Flatten output array
canny_flat = canny_arr.flatten()
return canny_flat
但是,當我使用示例圖像調用該函數時,輸出只是一個很大的0數組。 我確定那是不對的。 我已經在圖像上測試了canny算法,得到的圖像是正確的。 但是問題是當我想獲取圖像的矢量時。
有人能幫忙嗎?
我懷疑問題可能在那一行:
edge_canny = feature.canny(RGB, 3).astype(int)
請替換為
edge_canny = feature.canny(RGB, 3)
print(edge_canny)
edge_canny = edge_canny.astype(int)
print(edge_canny)
並檢查其打印內容,如果第一個是一些非零浮點值<1.0
,第二個是0
s,則可能意味着feature.canny
會生成從0.0
到1.0
值,然后將其轉換為int
會丟失。 編輯:修復了我的代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.