當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python skimage.morphology.thin用法及代碼示例

用法:

skimage.morphology.thin(image, max_num_iter=None)

執行二值圖像的形態細化。

參數

image二進製(M,N)ndarray

要細化的圖像。

max_num_iterint 迭代次數,可選

無論此參數的值如何,如果迭代沒有產生變化,則立即返回細化的圖像。如果指定了此參數,則它會設置執行迭代次數的上限。

返回

out布爾數組

變薄的圖像。

其他參數

max_iterDEPRECATED

已棄用以支持max_num_iter。

注意

該算法 [1] 的工作原理是在圖像上進行多次傳遞,刪除與一組旨在細化連接區域的標準相匹配的像素,同時保留 eight-connected 組件和 2 x 2 正方形 [2] 。在兩個sub-iterations 中的每一個中,該算法將中間骨架圖像與鄰域掩碼相關聯,然後在查找表中查找每個鄰域,指示是否應刪除該sub-iteration 中的中心像素。

參考

1

Z. Guo and R. W. Hall, “Parallel thinning with two-subiteration algorithms,” Comm. ACM, vol. 32, no. 3, pp. 359-373, 1989. DOI:10.1145/62065.62074

2

Lam, L., Seong-Whan Lee, and Ching Y. Suen, “Thinning Methodologies-A Comprehensive Survey,” IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol 14, No. 9, p. 879, 1992. DOI:10.1109/34.161346

例子

>>> square = np.zeros((7, 7), dtype=np.uint8)
>>> square[1:-1, 2:-2] = 1
>>> square[0, 1] =  1
>>> square
array([[0, 1, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
>>> skel = thin(square)
>>> skel.astype(np.uint8)
array([[0, 1, 0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]], dtype=uint8)

相關用法


注:本文由純淨天空篩選整理自scikit-image.org大神的英文原創作品 skimage.morphology.thin。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。