Adjust to changes in lighting conditions to maintain consistent color perception despite variations in light sources. More...
#include <peak_ipl/algorithm/peak_ipl_chromatic_adaption.hpp>
Public Types | |
| enum class | ColorSpace { SRGB_D50 = PEAK_IPL_CHROMATIC_ADAPTER_COLOR_SPACE_SRGB_D50 , SRGB_D65 = PEAK_IPL_CHROMATIC_ADAPTER_COLOR_SPACE_SRGB_D65 , CIE_RGB_E = PEAK_IPL_CHROMATIC_ADAPTER_COLOR_SPACE_CIE_RGB_E , ECI_RGB_D50 = PEAK_IPL_CHROMATIC_ADAPTER_COLOR_SPACE_ECI_RGB_D50 , Adobe_RGB_D65 = PEAK_IPL_CHROMATIC_ADAPTER_COLOR_SPACE_ADOBE_RGB_D65 } |
| Enumeration that defines the available color spaces. More... | |
| enum class | Algorithm { Legacy = PEAK_IPL_CHROMATIC_ADAPTER_ALGORITHM_LEGACY , Bradford = PEAK_IPL_CHROMATIC_ADAPTER_ALGORITHM_BRADFORD } |
| Enumeration that defines the available chromatic adaption algorithms. More... | |
Public Member Functions | |
| ChromaticAdapter () | |
| Constructor for a new Chromatic Adapter instance. | |
| ~ChromaticAdapter () | |
| Destructor for the Chromatic Adapter. | |
| ChromaticAdapter (const ChromaticAdapter &other) | |
| Copy Constructor for a new Chromatic Adapter instance. | |
| ChromaticAdapter & | operator= (const ChromaticAdapter &other) |
| Copy assigment for Chromatic Adapter instance. | |
| ChromaticAdapter (ChromaticAdapter &&other) noexcept | |
| Move constructor for Chromatic Adapter instance. | |
| ChromaticAdapter & | operator= (ChromaticAdapter &&other) noexcept |
| Move assignment for Chromatic Adapter instance. | |
| ColorSpace | TargetColorSpace () const |
| Get the target color space. | |
| void | SetTargetColorSpace (ColorSpace colorSpace) |
| Set the target color space. | |
| Algorithm | AdaptionAlgorithm () const |
| Get the current algorithm used for chromatic adaption. | |
| void | SetAdaptionAlgorithm (Algorithm algorithm) |
| Set the algorithm used for chromatic adaption. | |
| Range< uint32_t > | TemperatureRange () const |
| Returns the allowed temperature range for the current combination of color space and algorithm. | |
| ColorCorrectionFactors | CalculateColorCorrectionMatrix (uint32_t colorTemperature, const ColorCorrectionFactors &correctionFactors=ColorCorrectionFactors::Identity()) const |
| Calculate the color correction factors for colorTemperature using the current algorithm and color space. | |
Adjust to changes in lighting conditions to maintain consistent color perception despite variations in light sources.
In industrial imaging, white balance can fail due to the lack of a neutral reference in the image, such as when the scene contains no gray or white areas, or when the colors are unevenly distributed (as in images dominated by a single color). In these cases, traditional white balance algorithms, like the gray world method, may fail to produce accurate color corrections.
Chromatic adaptation provides an alternative solution by adjusting the image’s colors based on the known or estimated correlated color temperature of the light source.
To ensure proper functioning of chromatic adaptation, it is crucial that the image processing pipeline is designed correctly. Chromatic adaptation should be performed on an image with linear color values, meaning it must occur before gamma correction. However, standardized color spaces require gamma-corrected color values for accurate color reproduction. Furthermore, most cameras require color correction for proper color representation.
As a result, the following image processing pipeline is recommended:
| Image Processing Pipeline |
|---|
The image pipeline can be configured before image processing begins. The sample code below shows how the necessary modules are set up to process images for the target color space sRGB D65, where the scene is illuminated by a light source with a correlated color temperature of 3600 K.
A gamma corrector is configured with a value of 2.2, which is appropriate for the target color space (sRGB).
The chromatic adapter is set to use the Bradford transform as its algorithm.
The color corrector is initialized with a custom color correction matrix, such as the HQ matrix for the camera's filter glass. Following this, the chromatic adaptation is applied to the matrix using the chromatic adapter and the light source's correlated color temperature of 3600 K.
Alternatively, the adapted color correction matrix can be calculated and applied in two steps. In this case, the second parameter is optional. If not provided, the resulting matrix will be the direct chromatic adaptation matrix.
Each image must be processed following the previously configured image pipeline and in the correct order. It can be processed in-place or by creating a new image, depending on the specific use case.
The following images demonstrate a setting, where an image with incandescent light is adapted to sRGB D65 color space using a correlated color temperature of 3600 K:
| Without chromatic adaption | With chromatic adaption |
|---|---|
|
|
Color constancy is the ability of the human visual system to perceive an object's color consistently, regardless of changes in lighting.
In computer vision, a Chromatic Adaptation Transform (CAT) is a mathematical transformation applied to an image to simulate this perceptual adjustment, ensuring color constancy under varying lighting.
Several algorithms are used to perform CAT, with the Bradford transform being among the most widely used algorithms for this adjustment.
The correlated color temperature (CCT) describes the color of a visible light source by comparing it to the light emitted by an ideal black body at a specific surface temperature, measured in Kelvin (K).
The following table provides example values:
| Light source | Color temperature |
|---|---|
| Light bulb (100 W) | 2700 - 2800 K |
| Halogen lamp | 3000 - 3500 K |
| Daylight (midday sun) | 5000 - 6500 K |
| Cloudy sky | 6500 - 7500 K |
For artificial light sources, a "white tone" is often specified, which refers to the perceived warmth or coolness of the light. This is opposite to the actual correlated color temperature. Warm light (reddish) has a lower color temperature, while cold light (bluish) has a higher color temperature.
| White tone | Correlated color temperature |
|---|---|
| Warm white | 2700 - 3500 K |
| Neutral white | 4000 - 5000 K |
| Cool white | 5000 - 6500 K |
|
strong |
Enumeration that defines the available chromatic adaption algorithms.
The algorithms use a CAT (chromatic adaptation transform) matrix for chromatic adaption. There are various available CATs describing the transformation.
| Enumerator | |
|---|---|
| Legacy | The legacy algorithm |
| Bradford | The Bradford CAT matrix algorithm. This is the default. |
|
strong |
Enumeration that defines the available color spaces.
A color space is a specific implementation of a color model, mapping colors to a defined range of values. For example, sRGB is a standardized color space based on the RGB color model, but it also defines color primaries, the white point, and gamma to ensure consistent color representation across various platforms and devices.
|
inline |
Constructor for a new Chromatic Adapter instance.
|
inline |
Destructor for the Chromatic Adapter.
|
inline |
Copy Constructor for a new Chromatic Adapter instance.
| [in] | other | The other instance to acquire a reference for. |
|
inlinenoexcept |
Move constructor for Chromatic Adapter instance.
Moves the instance from other to this, leaving other in an invalid state.
| [in] | other | The other instance to move. |
|
inline |
Get the current algorithm used for chromatic adaption.
The implemented algorithms are listed in the enum Algorithm.
|
inline |
Calculate the color correction factors for colorTemperature using the current algorithm and color space.
The optional parameter correctionFactors can be used if the chromatic adaption is to be applied in parallel with another color correction, e.g. the HQ matrix for the camera filter glass. The result will be a matrix multiplication of the initial CCM and the chromatic adaption. It can directly be used. When using the ColorCorrector module, it might be advantageous to adjust an already set CCM using the comfort function ColorCorrector::ApplyChromaticAdaption
| [in] | colorTemperature | The color temperature in Kelvin for which the factors are be. |
| [in] | correctionFactors | The input color correction matrix. Default is the identity matrix. |
|
inlinenoexcept |
Move assignment for Chromatic Adapter instance.
Moves the instance from other to this, leaving other in an invalid state.
| [in] | other | The other instance to move. |
|
inline |
Copy assigment for Chromatic Adapter instance.
Acquires a reference from other to this instance. If this instance already has a reference, it will be destroyed.
| [in] | other | The other instance to acquire a reference for. |
|
inline |
Set the algorithm used for chromatic adaption.
The available algorithms are listed in the enum Algorithm.
| [in] | algorithm | The algorithm to set. |
|
inline |
Set the target color space.
The available color spaces are listed in the enum ColorSpace.
| [in] | colorSpace | The color space to set. |
|
inline |
Get the target color space.
There are many available color spaces. The implemented color spaces are listed in the enum ColorSpace.
|
inline |
Returns the allowed temperature range for the current combination of color space and algorithm.