White balance¶
| Fact | Value |
|---|---|
| Also called | Neutral point white balance, Gray point, Click white balance |
| Status | Implemented and tested |
| Family | Enhancement, illumination and color |
| Engine | Browser |
| Type | Linear, color, neutral point channel gains |
| Output | Image |
| Operator shown as | color-transform (exact) |
| Support radius | 0 |
| Code | web/src/core/filters/enhancement/white-balance.ts, whiteBalanceFilter |
| Operator code | web/src/core/filters/enhancement/white-balance.ts, neutralGains |
Overview¶
White balance removes a color cast with one color you pick. The picked color should be neutral, such as a gray card, a white wall or a sheet of paper. The filter finds the gains that turn it gray and applies them to the whole image. Set the probe on the neutral object with the Probe tool, then press Use probe pixel.
How it works¶
- Pick the color of something that should be neutral.
- Decode it to linear light and compute its luminance.
- Compute for each channel the gain that brings it to that luminance.
- Multiply every pixel by the gains, in linear light.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(n_C\): Channel C of the neutral color
- \(Y_n\): The luminance of the neutral color
- \(g_C\): The gain of channel C
n is the picked neutral color and Y_n its luminance, with the BT.709 weights. The gain of each channel turns the neutral into the gray (Y_n, Y_n, Y_n), so it keeps its brightness and loses its color. All other colors get the same gains, which is the von Kries idea of scaling each channel on its own. With Linear light on, the default, the gains act on linear light values: decoded from sRGB, scaled, and encoded again. A change in the color of the light scales linear values, so this is the physical model. With it off, the gains scale the encoded values. A channel of the neutral at 0 gets gain 1.
A change in the color of the light multiplies each channel of a surface by about the same factor everywhere in the image. Undoing it needs one gain per channel, a diagonal matrix. That is the von Kries model of adaptation. One neutral surface is enough to find the gains, since its true color is known to be gray.
Kernel or operator¶
The Inspector shows the three gains for the current neutral color, and whether they act on linear or encoded values.
Algorithm¶
- Decode the neutral color to linear light, if Linear light is on.
- Compute its luminance and the three gains.
- Scale each channel by its gain, in linear light or on the encoded values.
- Encode back to sRGB and clip to 0 to 255.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Neutral color neutral |
#d2c8b4 | color | The color of something in the image that should be neutral gray or white. Take it from the image with the probe pixel. |
Linear light linearLight |
on | On or off | Scale the linear light values instead of the encoded sRGB values. |
Implementation¶
whiteBalanceFilter in web/src/core/filters/enhancement/white-balance.ts computes the gains with neutralGains. The color parameter has its own control: a hex field, the system color picker, and a button that takes the stored color of the image at the probe pixel.
Worked example¶
| Quantity | Value |
|---|---|
| Picked neutral, encoded | (239, 167, 93), #efa75d |
| Gains in linear light | (0.542, 1.211, 4.274) |
| The same pixel after the filter | (182, 182, 182) |
The neutral is the gray ramp at x = 128 in the warm chart of the figure. Its red is high and its blue low, so the gains lower red and raise blue. After the filter the pixel is gray, up to rounding.
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
- Needs a truly neutral object. Picking a colored object gives a new cast.
- One set of gains for the whole image, so mixed lighting stays mixed.
Artifacts
- Clipped highlights in channels whose gain is above 1.
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. The cases cover a warm and a cool neutral, a gray neutral that changes nothing, and both settings of Linear light.
web/src/core/filters/filters.test.tsweb/src/core/filters/run.test.tsweb/src/core/filters/enhancement/enhancement.test.ts
References¶
- Lindbloom, B. Chromatic adaptation, with the cone response matrices and the white points of ASTM E308-01. Web Archive copy of 14 March 2026. https://web.archive.org/web/20260314100017/http://brucelindbloom.com/Eqn_ChromAdapt.html