Label connected components in binary image
The functions bwlabel
, bwlabeln
, and
bwconncomp
all compute connected components for binary
images. bwconncomp
replaces the use of
bwlabel
and bwlabeln
. It uses
significantly less memory and is sometimes faster than the other
functions.
Function | Input Dimension | Output Form | Memory Use | Connectivity |
---|---|---|---|---|
bwlabel | 2-D | Label matrix with double-precision | High | 4 or 8 |
bwlabeln | N-D | Double-precision label matrix | High | Any |
bwconncomp | N-D | CC struct | Low | Any |
To extract features from a binary image using regionprops
with default connectivity, just pass BW
directly into
regionprops
using the command
regionprops(BW)
.
bwlabeln
uses the following general procedure:
Scan all image pixels, assigning preliminary labels to nonzero pixels and recording label equivalences in a union-find table.
Resolve the equivalence classes using the union-find algorithm [1].
Relabel the pixels based on the resolved equivalence classes.
[1] Sedgewick, Robert, Algorithms in C, 3rd Ed., Addison-Wesley, 1998, pp. 11-20.
bwconncomp
| bwlabel
| label2rgb
| labelmatrix
| regionprops