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:
-
Large components bigger than a globally determined threshold Small components smaller than a globally determined threshold f components 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 allSee Also
ComponentMeasurements DeleteSmallComponents DeleteBorderComponents Select MorphologicalComponents
Related Guides
Introduced in 2010
(8.0)
| Updated in 2016 (11.0)