Label connected components in 2-D 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.
| Input Dimension | Output Form | Memory Use | Connectivity | |
|---|---|---|---|---|
bwlabel | 2-D | Double-precision label matrix | High | 4 or 8 |
bwlabeln | N-D | Double-precision label matrix | High | Any |
bwconncomp | N-D | CC struct | Low | Any |
You can use the MATLAB® find function
in conjunction with bwlabel to return vectors of
indices for the pixels that make up a specific object. For example,
to return the coordinates for the pixels in object 2, enter the following:.
[r,c] = find(bwlabel(BW)==2)
You can display the output matrix as a pseudocolor indexed image.
Each object appears in a different color, so the objects are easier
to distinguish than in the original image. For more information, see label2rgb.
To extract features from a binary image using
regionprops with default connectivity, just
pass BW directly into
regionprops using the command
regionprops(BW).
The bwlabel function can take advantage of
hardware optimization for data types logical,
uint8, and single to run
faster. Hardware optimization requires marker and
mask to be 2-D images and
conn to be either 4 or 8.
bwlabel uses the general procedure outlined
in reference [1],
pp. 40-48:
Run-length encode the input image.
Scan the runs, assigning preliminary labels and recording label equivalences in a local equivalence table.
Resolve the equivalence classes.
Relabel the runs based on the resolved equivalence classes.
[1] Haralick, Robert M., and Linda G. Shapiro, Computer and Robot Vision, Volume I, Addison-Wesley, 1992, pp. 28-48.
bwconncomp | bwlabeln | bwselect | label2rgb | labelmatrix | regionprops