Skip to content

Chromatic adaptation

Fact Value
Also called Von Kries adaptation, Bradford transform, White point conversion
Status Implemented and tested
Family Enhancement, illumination and color
Engine Browser
Type Linear, color, cone space white point adaptation
Output Image
Operator shown as color-transform (exact)
Support radius 0
Code web/src/core/filters/enhancement/white-balance.ts, chromaticAdaptationFilter
Operator code web/src/core/color/adaptation.ts, adaptationMatrix

Overview

Chromatic adaptation converts colors seen under one light to how they would look under another. The eye does this on its own, which is why white paper looks white under both tungsten light and daylight. This filter models it with a von Kries type transform, such as Bradford, between two CIE illuminants.

Three panels: a color chart, the chart adapted from D65 to illuminant A with an orange cast, and the cast chart adapted back from A to D65, close to the original. Three panels: a color chart, the chart adapted from D65 to illuminant A with an orange cast, and the cast chart adapted back from A to D65, close to the original.
The chart, adapted from D65 to illuminant A with Bradford, and adapted back from A to D65.

How it works

  1. Convert each color from linear sRGB to XYZ.
  2. Convert XYZ to cone-like responses with the matrix of the method.
  3. Scale each response by the ratio of the target white to the source white.
  4. Convert back to XYZ and to linear sRGB.

Mathematical foundation

\[ \begin{gathered} M = M_{\text{XYZ}}^{-1} M_A^{-1} \begin{bmatrix} \rho_t / \rho_s & 0 & 0 \\ 0 & \gamma_t / \gamma_s & 0 \\ 0 & 0 & \beta_t / \beta_s \end{bmatrix} M_A\, M_{\text{XYZ}}, \quad (\rho, \gamma, \beta) = M_A\, W, \quad \text{from } \text{A} \text{ to } \text{D65} \end{gathered} \]

The formula shows the default parameter values.

where

  • \(M_{\text{XYZ}}\): The linear sRGB to XYZ matrix
  • \(M_A\): The cone response matrix of the method
  • \(W_s, W_t\): The XYZ white points of the source and target lights
  • \(\rho, \gamma, \beta\): The cone-like responses of a white

The color goes from linear sRGB to XYZ with M_XYZ, then to cone-like responses with M_A, the matrix of the method. There each response is scaled by the ratio of the target white W_t to the source white W_s, which is the von Kries idea. Then it goes back to XYZ and to linear sRGB. The white points are those of the CIE illuminants in ASTM E308-01, and the Bradford and von Kries matrices are those tabled by Lindbloom. XYZ scaling uses the identity for M_A. The whole chain is one 3 by 3 matrix, applied in linear light. The source white turns into the target white exactly.

Von Kries proposed that the eye adapts by scaling the response of each cone type on its own. The transforms differ in the space where this scaling happens. The Bradford matrix sharpens the responses and is the usual choice. XYZ scaling skips the cone space and is the least accurate. All steps are linear, so the whole chain is one 3 by 3 matrix.

Kernel or operator

The Inspector shows the 3 by 3 matrix in linear sRGB for the current lights and method.

Algorithm

  1. Look up the white points of the two illuminants.
  2. Build the adaptation matrix of the method and combine it with the sRGB matrices.
  3. Decode each pixel to linear light, multiply by the matrix, encode back and clip.

Parameters

Parameter Default Values Meaning
Light in the image source A, tungsten (2856 K) A, tungsten (2856 K), D50, horizon daylight, D55, mid-morning daylight, D65, noon daylight, D75, north sky daylight, F2, cool white fluorescent, F7, broadband daylight fluorescent, F11, narrow-band white fluorescent The CIE illuminant that lit the scene.
Target light target D65, noon daylight A, tungsten (2856 K), D50, horizon daylight, D55, mid-morning daylight, D65, noon daylight, D75, north sky daylight, F2, cool white fluorescent, F7, broadband daylight fluorescent, F11, narrow-band white fluorescent The CIE illuminant the colors should look as if under. D65 is the white of sRGB.
Method method Bradford Bradford, Von Kries, XYZ scaling The cone response space in which the white is adapted.

Implementation

chromaticAdaptationFilter in web/src/core/filters/enhancement/white-balance.ts builds its matrix with rgbAdaptation from web/src/core/color/adaptation.ts, which holds the white points and the cone matrices.

Worked example

Matrix Row 1 Row 2 Row 3
Bradford A to D65, XYZ (0.8446965, -0.1179225, 0.3948108) (-0.1366303, 1.1041226, 0.1291718) (0.0798489, -0.1348999, 3.1924009)
The same, linear sRGB (0.7613968, -0.4601884, -0.1059292) (0.0214409, 1.1749155, -0.0433360) (0.0512404, 0.1909489, 3.2049078)

The XYZ matrix matches the one Lindbloom tables for A to D65 with Bradford, 0.8446965, -0.1179225, 0.3948108 in its first row, to the seventh decimal. The filter applies the linear sRGB version. Its large blue gain in the third row undoes the yellow of tungsten light.

Complexity

  • Time: \(O(N)\)
  • Memory: \(O(1)\)

N is the number of pixels. The gains or the matrix are computed once per run.

Artifacts and limitations

Limitations

  • The light must match one of the listed illuminants.
  • Real lights differ from the CIE illuminants, so some cast can remain.

Artifacts

  • Clipping of saturated colors, which can leave the sRGB range.

Tests

The reference computes the same steps with NumPy on a small RGB test image with saturated, gray, black and white pixels, and compares all three channels. Before the cases are written, the XYZ matrices from A to D65 for all three methods must match Lindbloom's precomputed table to 1e-6. More tests check that the source white maps onto the target white, and that equal lights change nothing.

References