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.

Details and Options

  • 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 Truewhether to include corner neighbors
    Method "Connected"connectivity method
    Padding 0padding 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 allclose all

Basic Examples  (3)

Find the connected components in a binary image:

Connected component labels:

Connected components of a 3D image:

Options  (10)

CornerNeighbors  (3)

8-connected objects:

4-connected objects:

Connectedness in 3D:

Padding  (1)

By default, zero padding is used:

Using Padding->1, all components connected to the border are assumed to be connected:

Method  (6)

Find the bounding boxes of connected components:

Find the non-overlapping bounding disks:

Find components whose convex hulls do not overlap:

Non-overlapping convex components:

Label each component the same as its embedding component:

Applications  (2)

Count the number of bright spots, specifying an explicit thresholding value:

Count the number of pixels in each connected component of an image:

Neat Examples  (1)

Find connected regions in a map:

Wolfram Research (2008), MorphologicalComponents, Wolfram Language function, https://reference.wolfram.com/language/ref/MorphologicalComponents.html (updated 2012).

Text

Wolfram Research (2008), MorphologicalComponents, Wolfram Language function, https://reference.wolfram.com/language/ref/MorphologicalComponents.html (updated 2012).

CMS

Wolfram Language. 2008. "MorphologicalComponents." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2012. 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_2023_morphologicalcomponents, author="Wolfram Research", title="{MorphologicalComponents}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/MorphologicalComponents.html}", note=[Accessed: 19-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_morphologicalcomponents, organization={Wolfram Research}, title={MorphologicalComponents}, year={2012}, url={https://reference.wolfram.com/language/ref/MorphologicalComponents.html}, note=[Accessed: 19-March-2024 ]}