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 allBasic Examples (3)
Scope (7)
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:
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