Skip to main content

Module labelling

Module labelling 

Source
Expand description

Connected-component labelling and per-region measurements, following scipy.ndimage.label, find_objects, sum, mean, minimum, maximum and center_of_mass.

Labelling gives each connected group of foreground pixels its own number, so that objects can be counted and measured one by one. Two pixels are connected if a chain of foreground pixels links them, each step allowed by the structuring element (the cross for edge neighbours only, the 3 × 3 square to include diagonals). The classical two-pass algorithm assigns provisional labels in one raster scan, recording which of them touch in a union-find structure, and then replaces each by its representative.

See the book entry Morphology, distance transforms and labelling.

Structs§

Region
The measurements of one labelled region.

Functions§

label
Labels the connected components of a binary image (SciPy’s label). Returns the label image (0 for background, 1..=n for the components, numbered in the raster order of their first pixel) and the number of components n. structure must be symmetric with odd dimensions; cross gives 4-connectivity and square(3) 8-connectivity.
regions
Measures every region of a label image in one pass: area, bounding box and centroid, and with values the intensity sum, mean, extremes and weighted centre.