SelectComponents

SelectComponents[{image,lmat},crit]

selects components of image indicated by the label matrix lmat that satisfy crit, replacing other parts with black.

SelectComponents[image,crit]

selects connected components of image.

SelectComponents[,"prop",n]

computes the property "prop" and selects the first n in sorted order.

SelectComponents[,"prop",n,p]

sorts computed properties using the ordering function p.

Details and Options

  • SelectComponents can be used to select image components with specific desired characteristics. Selection may be performed on components' location, shapes, and intensity properties.
  • Component selection is also used to filter undesired image parts, including small, large, border touching, or specifically shaped components.
  • SelectComponents works with 2D or 3D images and label matrices.
  • A label matrix lmat is an array of non-negative integers, in which each integer represents a component, and 0 represents the background.
  • If the label matrix lmat is not given, it is computed using the connectivity of nonzero pixels in image.
  • SelectComponents selects components based on the given criteria crit. Components that are not selected are replaced with 0 (black) in both image and lmat.
  • Possible forms of crit include:
  • Largecomponents bigger than a globally determined threshold
    Smallcomponents smaller than a globally determined threshold
    fcomponents that satisfy f
  • When a pure function f is used, component properties can be accessed using #prop1, #prop2, . A component is selected if f returns True.
  • For the complete list of possible properties, see the reference page for ComponentMeasurements.
  • SelectComponents[{image,lmat},] returns a modified version of {image,lmat} where unselected components are replaced with 0.
  • SelectComponents[lmat,] can also be used to select components from a label matrix lmat.
  • SelectComponents[,"prop",n] computes "prop" for all components and returns the first n, sorted using Sort.
  • SelectComponents[,{"prop1","prop2",},n] computes and sorts multiple properties.
  • SelectComponents[,"prop",-n] returns the last n components.
  • SelectComponents takes a CornerNeighbors option. The default setting is CornerNeighbors->True.

Examples

open allclose all

Basic Examples  (3)

Select the outermost components in an image:

Select three smallest components:

Select 3D image components:

Scope  (7)

Use a single property to select components:

Use multiple properties:

Select large components from a binary image:

Select small components:

Select the six smallest components:

Select the six largest components:

Select components of a label matrix:

Options  (1)

CornerNeighbors  (1)

By default, SelectComponents considers diagonally adjacent corners to be connected:

Use CornerNeighborsFalse to assume otherwise:

Applications  (5)

Select all the border components:

Select all interior components:

Select the four roundest objects:

Find objects smaller than 500 pixels that have holes and do not touch an image border:

Extract segments belonging to numbers in an image of a calendar:

Find the river in a satellite image by selecting the longest component:

Wolfram Research (2010), SelectComponents, Wolfram Language function, https://reference.wolfram.com/language/ref/SelectComponents.html (updated 2016).

Text

Wolfram Research (2010), SelectComponents, Wolfram Language function, https://reference.wolfram.com/language/ref/SelectComponents.html (updated 2016).

CMS

Wolfram Language. 2010. "SelectComponents." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/SelectComponents.html.

APA

Wolfram Language. (2010). SelectComponents. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/SelectComponents.html

BibTeX

@misc{reference.wolfram_2024_selectcomponents, author="Wolfram Research", title="{SelectComponents}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/SelectComponents.html}", note=[Accessed: 17-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_selectcomponents, organization={Wolfram Research}, title={SelectComponents}, year={2016}, url={https://reference.wolfram.com/language/ref/SelectComponents.html}, note=[Accessed: 17-November-2024 ]}