Find 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.
To extract features from a binary image using regionprops
with default connectivity, just pass BW directly into
regionprops using the command
regionprops(BW).
To compute a label matrix having more memory-efficient data type (for
instance, uint8 versus double), use the
labelmatrix function on the output of
bwconncomp. See the documentation for each function for
more information.
The basic steps in finding the connected components are:
Search for the next unlabeled pixel, p.
Use a flood-fill algorithm to label all the pixels
in the connected component containing p.
Repeat steps 1 and 2 until all the pixels are labeled.