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


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

用法:

skimage.morphology.skeletonize(image, *, method=None)

計算二值圖像的骨架。

細化用於將二進製圖像中的每個連接組件減少為single-pixel 寬骨架。

參數

imagendarray,2D 或 3D

包含要骨架化的對象的二進製圖像。零代表背景,非零值是前景。

method{‘zhang’, ‘lee’},可選

使用哪種算法。 Zhang 的算法[Zha84] 僅適用於 2D 圖像,並且是 2D 的默認值。 Lee 的算法[Lee94] 適用於 2D 或 3D 圖像,是 3D 的默認算法。

返回

skeletonndarray

變薄的圖像。

參考

Lee94

T.-C. Lee, R.L. Kashyap and C.-N. Chu, Building skeleton models via 3-D medial surface/axis thinning algorithms. Computer Vision, Graphics, and Image Processing, 56(6):462-478, 1994.

Zha84

A fast parallel algorithm for thinning digital patterns, T. Y. Zhang and C. Y. Suen, Communications of the ACM, March 1984, Volume 27, Number 3.

例子

>>> X, Y = np.ogrid[0:9, 0:9]
>>> ellipse = (1./3 * (X - 4)**2 + (Y - 4)**2 < 3**2).astype(np.uint8)
>>> ellipse
array([[0, 0, 0, 1, 1, 1, 0, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 1, 1, 1, 0, 0, 0]], dtype=uint8)
>>> skel = skeletonize(ellipse)
>>> skel.astype(np.uint8)
array([[0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)

相關用法


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