A white object under colored light
A sheet of white paper can appear neutral to an observer under different illuminants, while a camera's linear red, green and blue sensor values change with the light. White balance adjusts the channel balance to produce a chosen neutral response. It is a processing choice informed by a model: it does not by itself recover an object's physical reflectance or guarantee that all colors match their appearance under another light.
For a Lambertian surface patch under a common illuminant, an ideal linear sensor channel may be represented as
where is exposure, is incident spectral illumination, is surface spectral reflectance and is channel sensitivity. Geometric factors common to all three channels can be absorbed into . We use black-level-corrected, unsaturated values before nonlinear display encoding. This simplified integral ignores interreflection, specular highlights and spatially varying illumination; real filter sensitivities usually overlap.
A known neutral reference
Suppose a reference patch has spectrally flat reflectance over the relevant wavelengths and is measured as with each .
Definition 1.23.1
(Diagonal white-balance correction)
A diagonal correction multiplies the linear channels by positive gains :
It is a white balance for the reference patch when it maps to a neutral value with .
Proposition 1.23.2
(Gains from a neutral reference)
Let have all and let be a chosen target. The unique positive diagonal gains that give are
Positive gains that map to a neutral value are exactly times these.
Proof
(Solving channel by channel)
The condition means for each . Since , this forces , and these values do satisfy the condition. Taking gives .
Proof X-ray
What a diagonal correction can and cannot guarantee
For a flat reference with , its channel values are proportional to . The gain ratios therefore compensate that reference's unequal channel responses. For an arbitrary , the factors lie inside the spectral integrals. There is generally no reason that multiplying three integrals by fixed gains reproduces the integrals under a different illuminant for every possible reflectance. The neutral reference is balanced exactly in the ideal measurement; general color correction needs stronger assumptions or calibration.
Only neutrality is required, so the target is a free overall scale: white balance alone does not choose overall exposure. A practical convention is to keep green unchanged by choosing . A channel close to zero needs a large gain, which also amplifies its noise; clipping before or after the gain cannot be undone by the formula.
Worked example 1.23.3
(Balancing a measured patch)
A neutral patch gives in linear units. With , the gains are and the patch becomes . A nearby surface measured as becomes . This calculation assumes the same illuminant and an applicable diagonal correction at both positions. It does not show that the second surface has been physically relit correctly.
Worked example 1.23.4
(Changing the target and a nearly dark channel)
For the patch choose instead. The gains are , exactly half of the earlier gains, and the surface becomes , half of the earlier . Only the overall brightness changed, not the channel ratios. Edge case: if a patch were measured as , the gains for would be . Blue noise of standard deviation in the raw value then becomes after the gain, as large as the neutral target itself.
Common mistake
(Taking a clipped patch as the neutral reference)
Suppose a white patch has true channel values but the sensor clips at , so it is measured as . The gains for are then , whereas the correct gains are . Applied to the true patch the clipped-reference gains give , which is reddish rather than neutral. A reference must be measured below clipping in every channel.
Estimating from the scene: gray world
When no neutral patch is known, the gray-world heuristic assumes that the average scene response should be neutral after correction.
Definition 1.23.5
(Gray-world gains)
For a set of pixels whose arithmetic mean in each linear channel is , and a target , the gray-world gains are .
Proposition 1.23.6
(Gray-world gains neutralize the channel means)
After applying the gray-world gains, the mean of every corrected channel over the same pixels equals .
Proof
(Linearity of the average)
The mean of over the pixels is times the mean of , that is .
The statement is an imposed constraint, not evidence that the actual average reflectance is neutral. A scene dominated by green foliage or a colored wall can violate it. Excluding saturated, dark or specular pixels may improve a practical estimate, but the selection changes the statistic and needs a stated rule.
Worked example 1.23.7
(Gray world with a dominant color)
Take three linear pixels , and . The channel means are . With the gains are , and the pixels become , and , whose channel means are . The constant blue channel became a constant , so a feature of the scene was changed by the constraint. Edge case: if the blue channel were identically zero, then and no finite gain exists.
Counterexample mode
A blue scene is not necessarily blue lighting
Suppose every pixel in a black-level-corrected linear image is . Gray world with target applies gains , making every pixel . The data alone do not say whether a neutral scene was lit bluishly or a blue scene was viewed under neutral light. The algorithm makes the average neutral either way, and can remove genuine scene color.
More generally, a finite set of sensor values does not determine both illumination and reflectance spectra. Even a single scalar product is unchanged if a positive factor multiplies and divides , provided the resulting physical values remain admissible. More channels and assumptions help constrain the problem, but do not automatically identify the full spectra. White balancing in a gamma-encoded image also differs from multiplying linear values: in general, nonlinear encoding does not commute with gains. Perform and document the correction in its intended color space, and distinguish camera-channel gains from a subsequent color matrix and display transform.
Common mistake
(Applying linear gains to encoded values)
A gain chosen for linear sensor values changes the result differently once the image has been encoded. With and , the linear gain gives , but multiplying the encoded value by gives . The correction must be applied in the color space in which the gains were estimated.
Practice with solutions
Quick check
(A neutral patch measures . Preserve green and calculate gains and the corrected value of a surface measured as .)
Choose the target equal to the green value.
Solution · Answer
Gains are , giving . The reference itself maps to .
Quick check
(Two linear pixels are and . Apply gray world with target to their channel means and give the corrected pixels.)
Compute the channel means first.
Solution · Answer
Means are , so gains are . The corrected pixels are and ; each channel now averages . This does not validate the gray-world assumption.
Quick check
(A patch's red channel is zero. Can a finite diagonal gain map it to a strictly positive neutral target? What practical issue occurs when it is positive but very small?)
Multiply the red value by an arbitrary finite gain.
Solution · Answer
No: any finite gain times zero is zero. A tiny positive measurement requires a large gain and amplifies channel noise, making the estimate unstable.
Quick check
(An encoding is for . Compare encoding the gain-corrected linear value with multiplying the encoded value by , at . What does this show?)
Evaluate both orders of the two operations at .
Solution · Answer
, but . The operations need not commute; a gain designed for linear sensor values cannot simply be applied unchanged after an arbitrary nonlinear encoding. For this power law a linear gain corresponds to the encoded-domain gain : here .