Article sections
What is a digital image, and why is it more than a photograph in industry?RGB, HSV, Lab and grayscale: when should each be used?Is a pixel value the same as physical color?Metamerism: color matching under different lightsHistograms, white balance and 8/12/16-bit dataHow does a color sensor form an image?Interpreting Lab color differencesTesting the stability of color thresholdsFrequently asked questionsWhat is a digital image, and why is it more than a photograph in industry?
A digital image is a set of numerical measurements stored on a regular pixel grid. Each grayscale pixel usually contains one intensity value; a color image has multiple channels. The sensor converts light into electrical signals, and image-processing software operates on their numerical representation.
An 8-bit grayscale image generally uses values from 0 to 255. A 12-bit sensor can capture more intensity levels, but converting to 8 bits can discard some detail. Bayer reconstruction, white balance, gamma, compression and automatic exposure also affect the meaning of color-camera values. Two images of the same physical surface need not be numerically equivalent.
A human observer may ignore a slight brightness change. An algorithm seeing intensity 165 instead of 120 may make a different thresholding decision. An attractive image and a stable measurement image are different goals. In industrial use, repeatable acquisition often matters more than visual aesthetics.
Pixel, part and world coordinates are different
Most libraries place the pixel-coordinate origin at the top-left corner. A point at (u, v) = (950, 420) does not independently specify a physical location. Converting it to millimeters requires scale, image geometry and the measurement plane. Moving parts may also require transformations between part, conveyor and robot coordinate systems.
Make a practical distinction: detection asks whether a hole exists; localization asks where its center is; metrology asks how many millimeters its diameter measures and how trustworthy that result is. One image can support all three tasks, but their acceptable error levels differ.
RGB, HSV, Lab and grayscale: when should each be used?
Color-space selection determines which representation makes useful information easier to separate. No single color space is best for every industrial problem. Material surface, illumination and target defect influence the choice.
RGB / BGR. This is the familiar basis of color display. OpenCV commonly processes images in BGR order; this is a channel-order difference, not a quality difference. Searching for red regions in RGB can be straightforward, but thresholds tied to both color and illumination intensity can become fragile in production.
Grayscale. It is worth trying when geometry, contours, edges or texture distinguish the part without color information, potentially reducing memory and processing costs. However, distinct colors can map to similar gray values and lose discriminative information.
HSV. HSV separates hue (H), saturation (S) and value (V), helping inspect colored cables, labels, printing and caps. Shadows, specular reflections and low saturation still matter. Hue can become unstable when S is low. In OpenCV's common 8-bit conversion, H ranges from 0 to 179, which must be reflected in threshold code. OpenCV color conversions.
CIE Lab. Lab separates lightness from two opponent-color axes, offering useful features for comparing color shifts or coating shades. Numerically converting RGB to Lab is not, by itself, traceable color measurement. Demanding color inspection needs standardized illumination, a color reference and a calibrated system.

These channels describe the same image. A channel making a feature more visible does not automatically improve measurement. Validate the choice with samples from different shifts, production batches and lighting conditions.
| Inspected feature | Useful starting representation | What to watch |
|---|---|---|
| Metal-part silhouette, hole or edge | Grayscale / binary mask | Reflections, shadows, focus and perspective |
| Presence of a colored part or mark | HSV | Low saturation and hue drift |
| Coating color or color difference | Lab | Requires calibrated color acquisition |
| Fine surface scratches | Grayscale / local contrast / directional filter | Scratch direction and lighting geometry |
| Print and character inspection | Grayscale with local contrast | Glare, motion and character scale |
A transformation does not create missing information
If a scratch spans only a few pixels and produces nearly the same intensity as the surrounding surface, HSV, Lab and histogram equalization will not work miracles. They represent existing information differently. Insufficient source information requires changes to image acquisition. This can be more effective than spending hours tuning software parameters.
Is a pixel value the same as physical color?
A pixel value is not a fixed color property belonging to an object alone. Illumination spectrum, surface reflectance, sensor filters and in-camera processing jointly determine it. Different white-balance settings can make the same red plastic part appear more orange or purple. Stable acquisition is therefore as important as color-space choice in a color inspection system.
How do RGB, HSV and CIELAB answer different questions?
RGB carries red, green and blue components and fits naturally with cameras and displays. HSV separates hue, saturation and value, helping mask selected color ranges. CIELAB uses L* lightness, the green-red a* axis and the blue-yellow b* axis to support perceptual color-difference evaluation. No representation is universally best for every task.
| Space | Useful starting tasks | Potential misinterpretation |
|---|---|---|
| Grayscale | Contours, geometric features, texture and brightness differences | Different colors may produce similar gray values. |
| RGB/BGR | Color-image processing and channel comparisons | Can be directly sensitive to illumination changes. |
| HSV | Color-class masking and label detection | Hue is unstable at low saturation and is circular. |
| CIELAB | Color-tolerance assessment and comparisons | Reliable color differences require appropriate conversion and calibration. |
Metamerism: why can matching colors diverge under different lights?
Imagine two fabrics that match on the production line but look different under shop lighting. The samples have not changed; the spectrum illuminating them has. Illuminant metamerism occurs when samples with different spectral reflectance properties match in color for the same observer under one illuminant but not another. A match under one condition therefore does not establish a match under every light. [M1]
The essential distinction is that two samples are being compared. A single part looking different under warm and cool light does not, by itself, demonstrate metamerism. Different dyes or pigments can produce similar color responses under one source and diverge under another spectrum.

Does converting to HSV or Lab solve the problem?
No. A color-space conversion cannot recover spectral information the camera did not capture. Different reflectance spectra can produce the same three-component color values. A small color difference under one illuminant therefore does not guarantee a match under another. [M2]
The eye and camera are not the same observer. Camera-channel spectral sensitivities differ from the human standard-observer model. Disagreement between camera and visual assessment is another color-measurement risk and should not be confused with illuminant metamerism. A camera profile can help, but does not guarantee perfect agreement for every material and light source. [M3]
- Compare reference and production samples together under multiple lighting conditions defined for the application.
- Consider spectral properties, not just Kelvin ratings: similar color temperatures do not imply identical spectra.
- Record camera, exposure, white balance and viewing geometry. Do not mistake automatic-setting changes for material differences.
- For critical matching, evaluate spectral reflectance under specified illuminant and observer conditions. Do not present one RGB image as a metamerism measurement.
Histograms, white balance and 8/12/16-bit data
A histogram describes channel-value distribution and can reveal highlight saturation, shadow compression or batch drift. A full-image histogram can hide a small defect's local effect, so a fixed region of interest often gives more relevant information.
An 8-bit channel typically has 256 quantization levels. A 12-bit sensor provides more numerical levels, but high sensor noise can prevent a corresponding increase in usable information. Keep RGB and BGR order distinct: some libraries use BGR in memory, and fixed thresholds can behave unexpectedly if channels are confused.
How should color thresholds be validated?
Collect examples across shifts, batches and illumination conditions. Record white balance and exposure for each image. Verify separation on production boundary cases, not just teaching examples. Because red hue can straddle the hue scale's wraparound, two ranges may need to be combined instead of using one continuous threshold.
Mask only the cap before assessing its color; exclude the background. Use HSV for hue candidates, avoid relying on hue in low-saturation regions and compare changes against fixed reference samples. This is a stronger starting point than accepting whenever the RGB red channel is large.
How does a color sensor form an image?
In common single-sensor color cameras, differently filtered pixels sparsely sample spectral components. A Bayer sensor does not independently measure all three channels at each location; missing components are estimated from neighbors through demosaicing. Evaluate reconstruction artifacts when inspecting small colored details or fine edges.
Before applying color thresholds, distinguish raw sensor data, in-camera color correction and the saved file format. JPEG can change values near sharp color boundaries. Lossless data and controlled color conversion help where fixed color tolerances matter.
Interpreting Lab color differences
Comparing two colors in CIELAB supports color-difference metrics. The simplest, ΔE*ab or CIE76, is Euclidean distance in three dimensions. Since perceptual uniformity varies by color region, some applications prefer ΔE00. Such comparisons require standardized acquisition and appropriate white points and conversions.
For accepting colored plastic parts, understand acceptable-batch distributions and the measurement system's variability rather than deriving a threshold from one image. If gloss or texture direction changes pixel colors, compare multiple samples acquired by the same method.
Testing the stability of color thresholds
A color rule must work in production, not just in the laboratory. Use samples spanning acceptable variation rather than one ideal specimen per product color. Record drift caused by illumination aging, surface roughness and white-balance changes.
Inspect distributions from good products and defective or wrong-color products separately. Where distributions overlap, one threshold cannot eliminate both error types. A two-stage decision, additional spectral information or better-controlled illumination may be necessary. Acceptance tolerance, like color-space choice, must reflect production needs.
What information should accompany recorded color data?
At minimum, document light type and color, sensor, exposure, gain, white balance, conversion standard and file format. Identical RGB thresholds on different machines should not be assumed to represent identical physical colors. The goal is not an RGB value of 200, but stable discrimination of accepted material color.
Frequently asked questions
What is the difference between RGB and BGR?
The channel types are the same; their order in memory differs. An incorrect order leads to incorrect color interpretation.
Does HSV improve image quality?
No. It represents the same data on different axes and can simplify certain masking decisions.
When should grayscale be used?
It can be useful when color separation is unnecessary and contours, texture or brightness provide sufficient information.
Technical references
This article combines explanations supported by technical references with educational numerical examples. The example system values are not measurements from an actual facility.