This is documentation for Mathematica 7, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

MorphologicalComponents

MorphologicalComponents[image]
gives an array in which each pixel of image is replaced by an integer index representing the connected foreground image component in which the pixel lies.
MorphologicalComponents[image, t]
treats values above t as foreground.
  • The option setting CornerNeighbors->False treats only the four pixels in the coordinate directions as adjacent.
Connected component labels as a matrix:
Find the connected components in a binary image:
Specify an explicit threshold:
Connected component labels as a matrix:
In[1]:=
Click for copyable input
Out[1]//MatrixForm=
Find the connected components in a binary image:
In[2]:=
Click for copyable input
Out[2]=
 
Specify an explicit threshold:
In[1]:=
Click for copyable input
Out[1]=
Label matrix for 4-connected objects:
Count the number of pixels in each connected component of an image:
New in 7