bundles / skimage 0.26.1rc0.dev0+git20260530.b607368ff / skimage / measure / _label / label
function
skimage.measure._label:label
source: /dev/scikit-image/src/skimage/measure/_label.py :33
Signature
def label ( label_image , background = None , return_num = False , connectivity = None ) Summary
Label connected regions of an integer array.
Extended Summary
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
label_image: ndarray of dtype intImage to label.
background: int, optionalConsider 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, optionalWhether to return the number of assigned labels.
connectivity: int, optionalMaximum 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 ofinput.ndimis used.
Returns
labels: ndarray of dtype intLabeled array, where all connected regions are assigned the same integer value.
num: int, optionalNumber of labels, which equals the maximum label index and is only returned if return_num is
True.
Examples
import numpy as np x = np.eye(3).astype(int) print(x) print(label(x, connectivity=1)) print(label(x, connectivity=2)) print(label(x, background=-1)) x = np.array([[1, 0, 0], [1, 1, 5], [0, 0, 0]]) print(label(x))✓
See also
Aliases
-
skimage.morphology.label