skimage 0.17.2

ParametersReturnsBackRef
label(input, neighbors=None, background=None, return_num=False, connectivity=None)

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 a pixel/voxel a neighbor:

1-connectivity     2-connectivity     diagonal connection close-up

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

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 label them as 0. By default, 0-valued pixels are considered as background pixels.

return_num : bool, optional

Whether to return the number of assigned labels.

connectivity : int, optional

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

Returns

labels : ndarray of dtype int

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

num : int, optional

Number of labels, which equals the maximum label index and is only returned if return_num is :None:None:`True`.

Label connected regions of an integer array.

See Also

regionprops

Examples

This example is valid syntax, but we were not able to check execution
>>> import numpy as np
... x = np.eye(3).astype(int)
... print(x) [[1 0 0] [0 1 0] [0 0 1]]
This example is valid syntax, but we were not able to check execution
>>> print(label(x, connectivity=1))
[[1 0 0]
 [0 2 0]
 [0 0 3]]
This example is valid syntax, but we were not able to check execution
>>> print(label(x, connectivity=2))
[[1 0 0]
 [0 1 0]
 [0 0 1]]
This example is valid syntax, but we were not able to check execution
>>> print(label(x, background=-1))
[[1 2 2]
 [2 1 2]
 [2 2 1]]
This example is valid syntax, but we were not able to check execution
>>> x = np.array([[1, 0, 0],
...  [1, 1, 5],
...  [0, 0, 0]])
... print(label(x)) [[1 0 0] [1 1 2] [0 0 0]]
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

skimage.measure._label.label skimage.color.colorlabel._label2rgb_overlay skimage.color.colorlabel.label2rgb skimage.measure._regionprops.regionprops skimage.measure._regionprops.perimeter skimage.measure._regionprops._props_to_dict skimage.measure._regionprops.regionprops_table

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /skimage/measure/_label.py#4
type: <class 'function'>
Commit: