Detecting colors reliably can be challenging when objects are curved or illuminated unevenly from different directions. For example, consider a dice where each side should have similar colors. Inspecting the RGB values of two sides can produce very different results:
- Side with 1 point: RGB (248, 215, 201)
- Side with 3 points: RGB (123, 93, 81)
Using the RGB color space is ideal for cameras and displays, but it is often insufficient for accurate color discrimination in computer vision tasks.
Converting to HSV
A better approach is converting the image to the HSV (Hue, Saturation, Value) color space. HSV separates light intensity (Value) from Hue and Saturation, making color comparison more reliable:
- Side with 1 point: HSV (17, 18, 97)
- Side with 3 points: HSV (17, 34, 48)
By examining the individual HSV channels:
- Hue remains almost identical (17), confirming the same color
- Saturation shows minor differences (18 vs. 34)
- Value/light channel reflects the largest difference (97 vs. 48)
Using CIELAB for Color Clustering
For tasks where similar colors need clustering, converting to CIELAB color space provides improved separation:
- Side with 1 point: LAB (241, 125, 143)
- Side with 3 points: LAB (174, 129, 146)
Here, the L channel represents lightness, which helps to cluster colors while compensating for varying illumination.
Limitations
Even advanced color spaces have limitations. Overexposed areas cannot be reliably converted because sensor saturation causes irreversible information loss.
Business Benefits
- More accurate color detection in automated inspection
- Reliable classification for objects with complex shapes or uneven lighting
- Enhanced quality control in manufacturing and packaging
Optimize your computer vision system for color accuracy
Contact Subpixel at info@subpixel.hr to implement robust color detection using HSV, CIELAB, and custom image processing pipelines.