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.
MorphologicalComponents[video,…]
computes connected components in frames of video.
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.
MorphologicalComponents[video,…]
computes connected components in frames of video.
Details and Options
- MorphologicalComponents, also known as image connected components, is a binary image segmentation technique that segments image foreground based on pixel connectivity.
- MorphologicalComponents assigns sequential integers to different connected components and 0 to pixels that correspond to the background in the image.
- MorphologicalComponents[image] is equivalent to MorphologicalComponents[image,0].
- MorphologicalComponents works with binary, grayscale, and other images.
- The following options can be specified:
-
CornerNeighbors True whether to include corner neighbors Method "Connected" connectivity method Padding 0 padding method to use - The following Method settings can be specified:
-
"Connected" labels connected components "Nested" labels nested connected components "Convex" labels objects within non-overlapping convex regions "ConvexHull" finds non-overlapping convex hulls "BoundingBox" finds non-overlapping bounding boxes "BoundingDisk" finds non-overlapping bounding disks - MorphologicalComponents[image,Method->"Connected"] also works with Image3D objects.
Examples
open all close allBasic Examples (1)
Scope (4)
MorphologicalComponents[[image]]//ColorizeSegment a grayscale image, using all nonzero pixels as foreground:
MorphologicalComponents[[image]]//ColorizeSpecify a background threshold:
MorphologicalComponents[[image], .2]//ColorizeMorphologicalComponents[(| | | | |
| - | - | - | - |
| 0 | 0 | 1 | 2 |
| 0 | 0 | 3 | 4 |
| 5 | 0 | 0 | 0 |
| 6 | 7 | 0 | 0 |)] // MatrixFormConnected components of a 3D image:
MorphologicalComponents[[image]]//ColorizeOptions (10)
CornerNeighbors (3)
MorphologicalComponents[[image]]//MatrixFormMorphologicalComponents[[image], CornerNeighbors -> False] // MatrixFormi = [image];Colorize@MorphologicalComponents[i, CornerNeighbors -> #]& /@ {True, False}Method (6)
By default the "Connected" method is used:
MorphologicalComponents[[image]]// ColorizeFind the bounding boxes of connected components:
MorphologicalComponents[[image], Method -> "BoundingBox"]// ColorizeFind the non-overlapping bounding disks:
MorphologicalComponents[[image], Method -> "BoundingDisk"]// ColorizeFind components whose convex hulls do not overlap:
MorphologicalComponents[[image], Method -> "Convex"]// ColorizeNon-overlapping convex components:
MorphologicalComponents[[image], Method -> "ConvexHull"]// ColorizeLabel each component the same as its embedding component:
MorphologicalComponents[[image], Method -> "Nested"]//ColorizePadding (1)
By default, zero padding is used:
i = [image];MorphologicalComponents[i]//ColorizeUsing Padding->1, all components connected to the border are assumed to be connected:
MorphologicalComponents[i, Padding -> 1]//ColorizeApplications (2)
Tech Notes
History
Introduced in 2008 (7.0) | Updated in 2010 (8.0) ▪ 2012 (9.0) ▪ 2025 (14.2)
Text
Wolfram Research (2008), MorphologicalComponents, Wolfram Language function, https://reference.wolfram.com/language/ref/MorphologicalComponents.html (updated 2025).
CMS
Wolfram Language. 2008. "MorphologicalComponents." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/MorphologicalComponents.html.
APA
Wolfram Language. (2008). MorphologicalComponents. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MorphologicalComponents.html
BibTeX
@misc{reference.wolfram_2026_morphologicalcomponents, author="Wolfram Research", title="{MorphologicalComponents}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/MorphologicalComponents.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_morphologicalcomponents, organization={Wolfram Research}, title={MorphologicalComponents}, year={2025}, url={https://reference.wolfram.com/language/ref/MorphologicalComponents.html}, note=[Accessed: 13-June-2026]}