autodataming的个人博客分享 http://blog.sciencenet.cn/u/autodataming

博文

skimage.morphology.label

已有 4407 次阅读 2018-2-1 19:29 |系统分类:科研笔记

http://scikit-image.org/docs/dev/api/skimage.morphology.html#skimage.morphology.label


label的函数的功能是根据相邻情况从左到右 从上到下划分区域,并对区域建立索引。

label

skimage.morphology.label(input, neighbors=None, background=None, return_num=False, connectivity=None)[source]

Label connected regions of an integer array.

Two pixels are connected when they are neighbors and have the same value.In 2D, they can be neighbors either in a 1- or 2-connected sense.The value refers to the maximum number of orthogonal hops to consider apixel/voxel a neighbor:

1-connectivity2-connectivitydiagonalconnectionclose-up[][][][][]|               \  |/|<-hop2[]--[x]--[][]--[x]--[][x]--[]|/|  \         hop1[][][][]
Parameters:

input : ndarray of dtype int

Image to label.

neighbors : {4, 8}, int, optional

Whether to use 4- or 8-“connectivity”.In 3D, 4-“connectivity” means connected pixels have to share face,whereas with 8-“connectivity”, they have to share only edge or vertex.Deprecated, use ``connectivity`` instead.

background : int, optional

Consider all pixels with this value as background pixels, and labelthem as 0. By default, 0-valued pixels are considered as backgroundpixels.

return_num : bool, optional

Whether to return the number of assigned labels.

connectivity : int, optional

Maximum number of orthogonal hops to consider a pixel/voxelas a neighbor.Accepted values are ranging from  1 to input.ndim. If None, a fullconnectivity of input.ndim is used.

Returns:

labels : ndarray of dtype int

Labeled array, where all connected regions are assigned thesame integer value.

num : int, optional

Number of labels, which equals the maximum label index and is onlyreturned if return_num is True.

See also

regionprops

References

[R726727]Christophe Fiorio and Jens Gustedt, “Two linear time Union-Findstrategies for image processing”, Theoretical Computer Science154 (1996), pp. 165-181.
[R727727]Kensheng Wu, Ekow Otoo and Arie Shoshani, “Optimizing connectedcomponent labeling algorithms”, Paper LBNL-56864, 2005,Lawrence Berkeley National Laboratory (University of California),http://repositories.cdlib.org/lbnl/LBNL-56864

Examples

>>> importnumpyasnp>>> 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]]




https://blog.sciencenet.cn/blog-950202-1098036.html

上一篇:keras save model
下一篇:vscode 安装restructuredtext
收藏 IP: 202.127.19.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-17 17:22

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部