bwconncomp
Find and count connected components in binary image
Description
finds and counts the connected components CC
= bwconncomp(BW
)CC
in the binary
image BW
. The CC
output structure contains
the total number of connected components, such as regions of interest (ROIs), in the
image and the pixel indices assigned to each component.
bwconncomp
uses a default connectivity of 8 for two
dimensions and 26 for three dimensions.
Examples
Input Arguments
Output Arguments
Tips
This function sorts the connected components from left to right based on the
top-left
extremum of each component. When multiple components have the same horizontal position, the function then sorts those components from top to bottom, and again along any higher dimensions. This figure illustrates the extrema of two different regions.The functions
bwlabel
,bwlabeln
, andbwconncomp
all compute connected components for binary images.bwconncomp
uses significantly less memory and is sometimes faster than the other functions.To extract features from a binary image using
regionprops
with default connectivity, passBW
directly intoregionprops
using the commandregionprops(BW)
.To compute a label matrix having more memory-efficient data type (for instance,
uint8
versusdouble
), use thelabelmatrix
function on the output ofbwconncomp
.