ImageForestingComponents
✖
ImageForestingComponents
finds a segmentation of image, returning an integer matrix in which positive integers label different components.
tries to find a segmentation into components that include pixels indicated by marker.
finds components that are connected at a pixel scale given by r.
Details

- ImageForestingComponents[image,marker] generates a graph-based segmentation of image, starting with the pixels specified by marker.
- ImageForestingComponents works with arbitrary 2D and 3D images.
- The target region marker can be any of the following:
-
markerimage a marker image {pos1,pos2,…} a list of positions - Positions posi are assumed to be in the standard image coordinate system.
- Nonzero elements of marker are treated as weighted seeds for the segmentation.
- ImageForestingComponents produces a complete segmentation, assigning each pixel to a foreground component.
- ImageForestingComponents[image,marker,r] generates a segmentation where pixels in each component are connected within the radius r. The default radius setting is 2.
- ImageForestingComponents[image,marker,{r1,r2}] specifies different radii in vertical and horizontal directions.

Background & Context
- ImageForestingComponents returns an array of integers obtained through application of the image foresting transform (IFT). This transform provides a way to “segment” (separate) images into indexed components, each of which contains pixels having a “similar” color. The image foresting transform operates by constructing a graph in which neighboring pixels are joined by edges having weights proportional to the similarity of their colors and then partitioning this graph.
- Like other segmentation functions, ImageForestingComponents returns a “label array” in which each pixel is replaced by an integer corresponding to the component in which that pixel appears. A characteristic of ImageForestingComponents is that every pixel is assigned to some component. This means there is no separate “background”. Unlike some other segmentation schemes, ImageForestingComponents works in full color space without converting to intensity values.
- The image foresting transform is particularly good at segmenting images in which there is a high contrast between the segments to be separated.
- Other image segmentation functions include MorphologicalComponents and ClusteringComponents. The array returned by ImageForestingComponents may be visualized using Colorize and related functions.
Examples
open allclose allBasic Examples (2)Summary of the most common use cases
Scope (2)Survey of the scope of standard use cases
Use a set of marker positions as the marker:

https://wolfram.com/xid/0eluy88wiqd0y6b-p774b2


https://wolfram.com/xid/0eluy88wiqd0y6b-c6cb6q


https://wolfram.com/xid/0eluy88wiqd0y6b-cva9tp

https://wolfram.com/xid/0eluy88wiqd0y6b-5acp69

Use a larger connectivity radius:

https://wolfram.com/xid/0eluy88wiqd0y6b-etpqxq

Use a horizontally long connectivity:

https://wolfram.com/xid/0eluy88wiqd0y6b-19tbqm

Use a vertically long connectivity:

https://wolfram.com/xid/0eluy88wiqd0y6b-zpkyj1

Applications (4)Sample problems that can be solved with this function
Segment an image using a set of seeds:

https://wolfram.com/xid/0eluy88wiqd0y6b-bffgjm

Determine a region of interest in a 3D image with ImageForestingComponents using markers:

https://wolfram.com/xid/0eluy88wiqd0y6b-4329pp
Use this mask to highlight the organs in the image:

https://wolfram.com/xid/0eluy88wiqd0y6b-y06bnd

Use a rectangular neighborhood to segment lines of a text:

https://wolfram.com/xid/0eluy88wiqd0y6b-djo77r

Segment different words in a group of text:

https://wolfram.com/xid/0eluy88wiqd0y6b-ftl6zo


https://wolfram.com/xid/0eluy88wiqd0y6b-y0ouo1

Wolfram Research (2010), ImageForestingComponents, Wolfram Language function, https://reference.wolfram.com/language/ref/ImageForestingComponents.html (updated 2025).
Text
Wolfram Research (2010), ImageForestingComponents, Wolfram Language function, https://reference.wolfram.com/language/ref/ImageForestingComponents.html (updated 2025).
Wolfram Research (2010), ImageForestingComponents, Wolfram Language function, https://reference.wolfram.com/language/ref/ImageForestingComponents.html (updated 2025).
CMS
Wolfram Language. 2010. "ImageForestingComponents." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/ImageForestingComponents.html.
Wolfram Language. 2010. "ImageForestingComponents." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/ImageForestingComponents.html.
APA
Wolfram Language. (2010). ImageForestingComponents. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ImageForestingComponents.html
Wolfram Language. (2010). ImageForestingComponents. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ImageForestingComponents.html
BibTeX
@misc{reference.wolfram_2025_imageforestingcomponents, author="Wolfram Research", title="{ImageForestingComponents}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/ImageForestingComponents.html}", note=[Accessed: 25-April-2025
]}
BibLaTeX
@online{reference.wolfram_2025_imageforestingcomponents, organization={Wolfram Research}, title={ImageForestingComponents}, year={2025}, url={https://reference.wolfram.com/language/ref/ImageForestingComponents.html}, note=[Accessed: 25-April-2025
]}