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


selects connected components of image.


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


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.


open all close all

Basic Examples  (3)

Select the outermost components in an image:

Click for copyable input

Select three smallest components:

Click for copyable input

Select 3D image components:

Click for copyable input

Scope  (7)

Options  (1)

Applications  (5)

Introduced in 2010
Updated in 2016