bwlabel
Label connected components in 2-D binary image
Description
Examples
Input Arguments
Output Arguments
Tips
This function sorts the connected components from left to right based on the
top-leftextremum of each component. When multiple components have the same horizontal position, the function then sorts those components from top to bottom. This figure illustrates the extrema of two different regions.The functions
bwlabel,bwlabeln, andbwconncompall compute connected components for binary images.bwconncompuses significantly less memory and is sometimes faster than the other functions.Input Dimension Output Form Memory Use Connectivity bwlabel2-D Double-precision label matrix High 4 or 8 bwlabelnN-D Double-precision label matrix High Any bwconncompN-D CC struct Low Any You can use the MATLAB®
findfunction in conjunction withbwlabelto 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
regionpropswith default connectivity, passBWdirectly intoregionpropsusing the commandregionprops(BW).The
bwlabelfunction can take advantage of hardware optimization for data typeslogical,uint8, andsingleto run faster. Hardware optimization requiresmarkerandmaskto be 2-D images andconnto 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

