Color Segmentation
- Updated2025-11-25
- 3 minute(s) read
Color segmentation compares the color feature of each pixel with the color features of surrounding pixels or a trained color classifier to segment an image into color regions. Use color segmentation to separate color objects of interest from background clutter.
You can use color segmentation in a wide variety of machine vision applications, such as the following:
A
B
Concepts
Color segmentation involves three stages.
- Train a color classifier with color samples for your application.
- Segment an image into different color regions. Color segmentation consists of
the following steps.
- Move an inspection window across the image to calculate the color
feature of each pixel.
- Pivot Pixel
- Inspection Window
- Image
- Compare the color feature for each inspection window with the color feature of neighboring windows.
- If the closest distance between the inspection window and a neighboring
window is less than maximum distance, apply the color label from the
pivot pixel in the neighboring window to the pivot pixel in the
inspection window.
- Distance Between Neighboring Color Features Exceeds Maximum Distance
- Distance Between Neighboring Color Features Does Not Exceed MaximumDistance
- If the closest distance between the inspection window and a neighboring
window is greater than maximum distance, use the color classifier to
label the pivot pixel in the inspection window.
- Distance Between Neighboring Color Features Exceeds Maximum Distance
If the identification score for the inspection window is less than the minimum identification score, the color classification algorithm does not label the pivot pixel.
- Move an inspection window across the image to calculate the color
feature of each pixel.
- Filter segmented regions to eliminate regions that do not meet the specified size requirements.
In-Depth Discussion
Maximum distance refers to the maximum distance allowed between the color features of pivot pixels with the same color label. Maximum distance is calculated from the trained color classifier as:
An aggressive maximum distance defines the distance between the two closest trained classes as the median distance between samples in each class. A conservative maximum distance defines the distance between the two closest trained classes as the smallest distance between samples in each class. A high maximum distance typically allows more pixels to use the color label of neighboring pixels, which avoids using the color classifier and decreases the time required to perform color segmentation. A high maximum distance reduces the accuracy of color segmentation.
Color segmentation can be time-consuming if it operates on each pixel. To increase the speed of color segmentation increase the step size, which increases the offset between each inspection window, or train color samples at a lower color resolution to reduce the size of the color feature for each color class.