当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。