bwlabel
Label connected components in 2-D binary image
Description
Examples
Input Arguments
Output Arguments
Tips
The functions
bwlabel
,bwlabeln
, andbwconncomp
all compute connected components for binary images.bwconncomp
replaces the use ofbwlabel
andbwlabeln
. 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 withbwlabel
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 passBW
directly intoregionprops
using the commandregionprops(BW)
.The
bwlabel
function can take advantage of hardware optimization for data typeslogical
,uint8
, andsingle
to run faster. Hardware optimization requiresmarker
andmask
to be 2-D images andconn
to be either 4 or 8.
Algorithms
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.
References
[1] Haralick, Robert M., and Linda G. Shapiro, Computer and Robot Vision, Volume I, Addison-Wesley, 1992, pp. 28-48.
Extended Capabilities
Version History
Introduced before R2006aSee Also
bwconncomp
| bwlabeln
| bwselect
| labelmatrix
| label2rgb
| regionprops