用法:
skimage.feature.canny(image, sigma=1.0, low_threshold=None, high_threshold=None, mask=None, use_quantiles=False, *, mode='constant', cval=0.0)
使用 Canny 算法對圖像進行邊過濾。
- image:二維數組
灰度輸入圖像以檢測邊;可以是任何 dtype。
- sigma:浮點數,可選
高斯濾波器的標準偏差。
- low_threshold:浮點數,可選
滯後閾值(鏈接邊)的下限。如果沒有,low_threshold 設置為 dtype 最大值的 10%。
- high_threshold:浮點數,可選
滯後閾值的上限(鏈接邊)。如果沒有,high_threshold 設置為 dtype 最大值的 20%。
- mask:數組,dtype=bool,可選
將 Canny 的應用限製在某個區域的掩碼。
- use_quantiles:布爾型,可選
如果
True
則將 low_threshold 和 high_threshold 視為邊幅度圖像的分位數,而不是絕對邊幅度值。如果True
則閾值必須在 [0, 1] 範圍內。- mode:字符串,{‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}
mode
參數確定在高斯濾波期間如何處理數組邊界,其中cval
是模式等於 ‘constant’ 時的值。- cval:浮點數,可選
如果模式為‘constant’,則填充過去輸入邊的值。
- output:二維數組(圖像)
二元邊圖。
參數:
返回:
注意:
該算法的步驟如下:
- 使用具有
sigma
寬度的高斯平滑圖像。 - 應用水平和垂直 Sobel 算子來獲得圖像中的漸變。邊強度是梯度的範數。
- 將潛在邊細化到 1 像素寬的曲線。首先,在每個點找到邊的法線。這是通過查看X-Sobel 和Y-Sobel 的符號和相對幅度來完成的,將點分為4 類:水平、垂直、對角線和對角線。然後查看正常和反向方向,看看其中任何一個方向的值是否大於所討論的點。使用插值來獲得混合點,而不是選擇最接近法線的點。
- 執行滯後閾值處理:首先將高於高閾值的所有點標記為邊。然後遞歸地將任何高於低閾值的點標記為 8 連接到標記點作為邊。
參考:
- 1
Canny, J., A Computational Approach To Edge Detection, IEEE Trans. Pattern Analysis and Machine Intelligence, 8:679-714, 1986 DOI:10.1109/TPAMI.1986.4767851
- 2
William Green’s Canny tutorial https://en.wikipedia.org/wiki/Canny_edge_detector
例子:
>>> from skimage import feature >>> rng = np.random.default_rng() >>> # Generate noisy image of a square >>> im = np.zeros((256, 256)) >>> im[64:-64, 64:-64] = 1 >>> im += 0.2 * rng.random(im.shape) >>> # First trial with the Canny filter, with the default smoothing >>> edges1 = feature.canny(im) >>> # Increase the smoothing for better results >>> edges2 = feature.canny(im, sigma=3)
相關用法
- Python skimage.feature.corner_orientations用法及代碼示例
- Python skimage.feature.corner_subpix用法及代碼示例
- Python skimage.feature.corner_foerstner用法及代碼示例
- Python skimage.feature.corner_harris用法及代碼示例
- Python skimage.feature.corner_fast用法及代碼示例
- Python skimage.feature.corner_peaks用法及代碼示例
- Python skimage.feature.corner_moravec用法及代碼示例
- Python skimage.feature.corner_shi_tomasi用法及代碼示例
- Python skimage.feature.graycomatrix用法及代碼示例
- Python skimage.feature.blob_doh用法及代碼示例
- Python skimage.feature.blob_dog用法及代碼示例
- Python skimage.feature.graycoprops用法及代碼示例
- Python skimage.feature.structure_tensor用法及代碼示例
- Python skimage.feature.hessian_matrix用法及代碼示例
- Python skimage.feature.ORB用法及代碼示例
- Python skimage.feature.peak_local_max用法及代碼示例
- Python skimage.feature.CENSURE用法及代碼示例
- Python skimage.feature.hessian_matrix_eigvals用法及代碼示例
- Python skimage.feature.haar_like_feature_coord用法及代碼示例
- Python skimage.feature.BRIEF用法及代碼示例
注:本文由純淨天空篩選整理自scikit-image.org大神的英文原創作品 skimage.feature.canny。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。