Note: This page has been translated by MathWorks. Please click here

To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

Find connected components in binary image

`CC = bwconncomp(BW)`

`CC = bwconncomp(BW,conn)`

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.Function Input Dimension Output Form Memory Use Connectivity `bwlabel`

2-D Label matrix with double-precision High 4 or 8 `bwlabeln`

N-D Double-precision label matrix High Any `bwconncomp`

N-D `CC`

structLow Any To extract features from a binary image using

`regionprops`

with default connectivity, just pass`BW`

directly into`regionprops`

(i.e.,`regionprops(BW)`

).To compute a label matrix having more memory-efficient data type (e.g.,

`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 labelled.

Was this topic helpful?