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


Python skimage.morphology.label用法及代码示例


用法:

skimage.morphology.label(label_image, background=None, return_num=False, connectivity=None)

标记整数数组的连接区域。

当两个像素是相邻的并且具有相同的值时,它们是连接的。在 2D 中,它们可以是 1 或 2 连接意义上的邻居。该值是指将像素/体素视为邻居的最大正交跳数:

1-connectivity     2-connectivity     diagonal connection close-up

     [ ]           [ ]  [ ]  [ ]             [ ]
      |               \  |  /                 |  <- hop 2
[ ]--[x]--[ ]      [ ]--[x]--[ ]        [x]--[ ]
      |               /  |  \             hop 1
     [ ]           [ ]  [ ]  [ ]

参数

label_imagedtype int的ndarray

要标记的图像。

backgroundint 可选

将具有此值的所有像素视为背景像素,并将它们标记为 0。默认情况下,将 0 值像素视为背景像素。

return_num布尔型,可选

是否返回分配标签的数量。

connectivityint 可选

将像素/体素视为邻居的最大正交跳数。接受的值范围从 1 到 input.ndim 如果 None ,则使用 input.ndim 的完整连接。

返回

labelsdtype int的ndarray

标记数组,其中所有连接区域都分配有相同的整数值。

numint 可选

标签数,等于最大标签索引,仅在return_num 为 True 时返回。

其他参数

inputDEPRECATED

已弃用以支持label_image。

参考

1

Christophe Fiorio and Jens Gustedt, “Two linear time Union-Find strategies for image processing”, Theoretical Computer Science 154 (1996), pp. 165-181.

2

Kensheng Wu, Ekow Otoo and Arie Shoshani, “Optimizing connected component labeling algorithms”, Paper LBNL-56864, 2005, Lawrence Berkeley National Laboratory (University of California), http://repositories.cdlib.org/lbnl/LBNL-56864

例子

>>> import numpy as np
>>> x = np.eye(3).astype(int)
>>> print(x)
[[1 0 0]
 [0 1 0]
 [0 0 1]]
>>> print(label(x, connectivity=1))
[[1 0 0]
 [0 2 0]
 [0 0 3]]
>>> print(label(x, connectivity=2))
[[1 0 0]
 [0 1 0]
 [0 0 1]]
>>> print(label(x, background=-1))
[[1 2 2]
 [2 1 2]
 [2 2 1]]
>>> x = np.array([[1, 0, 0],
...               [1, 1, 5],
...               [0, 0, 0]])
>>> print(label(x))
[[1 0 0]
 [1 1 2]
 [0 0 0]]

相关用法


注:本文由纯净天空筛选整理自scikit-image.org大神的英文原创作品 skimage.morphology.label。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。