algorithmimage-processingcolorscielab

What is the math behind white balance algorithms?


I have an image in CIELab color space. I need to do some processing on it. So, there are two questions:

  1. Given an array of Lab values, how would one get overall image temperature in Kelvins? (Like in camera settings or in Lightroom)

  2. Having temperature value in Kelvins, how would one adjust image white balance to match that very temperature? (Like in Lightroom)

I would also like to know, how to do the same things for color tint.


Solution

  • The old (and stupid) method is to check the colour of most luminous pixels (but without highlights). This is assumed to be white. Fortunately, often there are white objects (check people eyes), so it works most of time.

    Just remove such colour cast on all pixels, and you have the white balanced image. [Note: this should be done in linear space].

    From the chromacity of white, you can derive the Kelvin: note: most programs allow WB in both a-b directions (so 2D, your "tint" extra question), not just one line (Temperature).

    Modern cameras are more smart: they check than no channels is clipped, they check that the chromacity is not far away from the black body emissions (so not far from just "temperature" parameter). And most modern cameras can distinguish the subject (e.g. with focus distance (so landscape), etc. to predict a better WB).

    A grey card is still the more reliable way: no algorithms can get true white balance.