Decoding White Balance

  • 6 Replies
  • 9317 Views
Decoding White Balance
« on: 18 / July / 2016, 23:56:51 »
Advertisements
Hello,
Just the results of investigating how white balance works.  I'm publishing this in case it's useful to someone (it's pretty advanced and technical though).

Motivation
I've been trying to profile read/dark noise, but found that white balance affects the noise level.  I wanted to calibrate the noise so I don't need to shoot dark frames, but generate them automatically from a ISO/Temperature model.  I can't adapt my model without being able to interpolate different WB's, and to do that I need to set specific RGB ratios.

What I Found
WB is a pretty complicated subject.  Luckily I have a camera that let's me modify a standard WB to one of 360 other settings.  There doesn't seem to be a simple formula to convert between RGB gain settings and WB/colour temperature, so I have to make do with tables of available values.

The modify WB setting isn't even documented for my camera, but there's some good info in the DNG standard that explains WB in general.

The camera allows 19 settings on two axis for modify a base WB.

The horizontal axis is 0 to 9 Blue, to 0 to 9 A (which is coloured Red)
The vertical axis is 0 to 9 Green to 0 to 9 Magenta
Increasing B reduces K (colour temperature), increasing A increases K
Increasing G reduces K a bit, increasing M increases K a bit
The lowest K is at b9,g9, the highest K is at a9,m9
Moving towards Blue makes the image bluer, moving towards A makes the image redder.

I made a table of R/G/B gain values and colour temperature (K) values, by shooting at various settings and reading the gain values from the .cr2 (RAW) file using exiftool(-k).exe.  Just look for the White Balance As Shot tag.


Code: [Select]
Daylight
          R    G    B    K
0,0    1557    937    1785    4963
b9,0    1270    897    2155    3779
b1,0    1517    935    1831    4787
a1,0    1600    940    1739    5157
a9,0    1956    936    1389    7336
0,g9    1442    1070    1636    4910
0,g1    1544    951    1770    4957
0,m1    1567    923    1803    4970
0,m9    1658    814    1932    5017
b9,g9    1204    1034    1946    3742
a9,m9    2137    810    1461    7422

Tungsten
         R    G    B    K
0,0    1056    745    2600    3180
b1,0    1034    739    2628    3113
b9,0    837    684    2939    2643

Reading This Table
The first column is the custom settings value.  Next are three numbers representing the analog gain on each colour of the image.  Then is the colour temperature that is supposed to be.

For example Daylight which is normally K=4963 can be modified from K=3742 to K=7422.
You can see how K affects RGB here
https://academo.org/demos/colour-temperature-relationship/
It's a javascript widget that lets you select K and render it's colour, and display equivalent RGB values.  K is orange for low values, then white around 6500, finally turning to blue at high values.

Remember that gain settings are just the opposite of the K->RGB colours.  For a low K like 3180 (Tungsten, which looks yellowish), you need to increase the gain of Blue dramatically to get a white colour, as you can see in the table, the gain for blue (2600) is much greater than the other colours, such as Red (1056).

What does the Green/Magenta axis do?
This one was pretty easy.  First of all, Green/Magenta are on opposite sides of the colour wheel, meaning Magenta is just a colour with Green subtracted from it, in other words this is just plus or minus Green.  If you look under Daylight at g9 (1070) and m9 (814) and subtract them, you get 256.  That means each step of Green is just 256/18 added to the base value.  This turns out to be approximate.

What is the A on the horizontal axis?
A may stand for Aqua or Azure, it makes no sense as blue's opposite is yellow and I can't think of an orangish colour that starts with A.  The B/A axis might refer to Lab colour, but that doesn't work because a is green to magenta and b is blue to yellow
« Last Edit: 19 / July / 2016, 00:20:24 by jmac698 »

Re: Decoding White Balance
« Reply #1 on: 27 / July / 2016, 14:16:43 »
I finally found a reference in the manual explaining the custom white balance.

B: blue; A: amber; M: magenta; G: green
One level of blue/amber correction is equivalent to about 7 mireds on a colour temperature conversion filter.

mired = micro reciprocal degree
the mired value of a light source is equal to '1,000,000 / X' where x equals the colour temperature in Kelvin

Example
1000000 / 5500 (photographic daylight) = 181 (approx)
 
 1000000 / 3200 (Tungsten studio lamp) = 312 (approx)
 
 181 - 312 = -131
 
 -131 is the mired shift value of wratten 80A and is generally used to balance tungsten (3200k) to daylight (5500k).
« Last Edit: 27 / July / 2016, 14:19:34 by jmac698 »

Re: Decoding White Balance
« Reply #2 on: 27 / July / 2016, 14:54:49 »
Code: [Select]
Daylight
      K    Mired
a9,0  7336 136.3
a1,0  5157 193.9
0,0   4963 201.5
b1,0  4787 208.9
b9,0  3779 264.6

128.3 Mireds/19 steps=6.75 Mireds/step

This still doesn't explain exactly how the adjustment works, as change in mireds is close to 7 but varies at each adjustment step.

Re: Decoding White Balance
« Reply #3 on: 07 / August / 2016, 12:14:11 »
Hello,
Lazy Sunday here and working on this investigation.  Here is code, working for SX50, to set every custom WB and take a shot.  Following this, one would have to write a script to process the RAW files with EXIFTOOL to extract the WB as Shot tags.

Code: [Select]
--[[
@title All WB
-- set custom WB for SX50 only
-- makes one shot of every cust WB setting
-- cust WB settings are modified from a base WB
-- so set desired WB then run
--]]

--This function is tested working, as long as
--  the set menu is left at the WB item in shoot mode
function setwb(a,b)
d=400
click ("set")
sleep (d)
click ("display")
sleep (d)
click ("menu")
sleep (d)
for x=1,math.abs(a) do
  if a<0 then click ("left")
  else click ("right")
  end
  sleep (d)
end
for x=1,math.abs(b) do
  if b<0 then click ("up")
  else click ("down")
  end
  sleep (d)
end
click ("set")
sleep (d)
end

--testing
--setwb(3,3)

for a=-9,9 do
for b=-9,9 do
setwb(a,b)
shoot()
--read WB
end
end





Re: Decoding White Balance
« Reply #4 on: 09 / August / 2016, 09:42:55 »
I've now extracted some of the custom WB values.

Starting with Daylight, I modified the WB from -9 (B9) to +9 (A9), then G/M from -9 (G9) to +9 (M9).  Going in this order, will change the colour temperature from lowest (3742, 267 Mireds) to highest (7422, 161 Mireds).  You can consider the horizontal Blue/Amber axis as a coarse adjustment, with the Green/Magenta as a fine adjustment.  Moving to the right and down increases colour temperature.

The left, extreme blue (B9) setting makes the image more blue - which is to correct for a yellowish/warm/low colour temperature cast to bring it to neutral.

The range of adjustment on Daylight can bring it to Flurorescent (B6M6, K=4093, ideal was 4091) or Cloudy (A4G7, K=5612, ideal is 5607).

Kodak Wratten filters were to bring natural light to look neutral/daylight for various films, such as daylight film or 3200 (for shooting with tungsten) film.  So late in the afternoon, you could start putting on filters to keep the colours looking like daylight.

I found the equivalent settings that give the same effect as the Wratten filters.  All of them can be simulated from a modified daylight WB.

Code: [Select]
Wratten    From    To    Change in Mireds    Colour Temp from Canon Daylight    Adj. From Daylight
80A    3200    5500    -131    4832    B1M7
80B    2400    5500    -235    4728    B1G9
80C    3800    5500    -81    4882    G9
80D    4200    5500    -56    4907    G9
85    5500    3400    112    5075    A1G9
85B    5500    5200    10    4973    M2
85C    5500    3800    81    5044    M9
82    3100    3200    -10    4953    G2
82A    3000    3200    -21    4942    G4
82C    2900    3200    -32    4931    G5
81    2800    3200    -45    4918    G8
81A    3300    3200    9    4972    M2
81B    3400    3200    18    4981    M3
81C    3500    3200    27    4990    M4
81D    3600    3200    35    4998    M6
81EF    2850    3200    -38    4925    G6

I should note, that there is better quality from shooting with the colour look that you want with the WB settings.  There will be less noise, because of analog gain control, and finer tints and dynamic range, because of fitting the result into limited bits.

I also want to mention the "Tungsten" in photo terms means high-powered Tungsten lamps, which had a colour temperature of 3200, not like household lightbulbs which have a lower temp.  These are both obsolete now anyhow.

The gain values seem to vary, but their proportions remain the same.  For example, in two different shots I got these values:

Code: [Select]
R    G    B    K    RB    BB
1712    1031    1963    4963    1.66    1.90
1557    937    1785    4963    1.66    1.91

You can see that it's very close.

Wratten filters and terminology is also obsolete, but I haven't researched the new system yet.

Finally, here's how to extract the values:
Code: [Select]
exiftool -MakerNotes:WB_RGGBLevelsAsShot -MakerNotes:ColorTempAsShot -csv *.cr2 > wb.txt
For my testing purposes, I wanted the most extreme WB Balances, so here's the best I've found so far:
Code: [Select]
R    G    B    K    B/A    G/M    RB
2079    899    1859    6054    5    9    2.31
1324    1137    2139    3742    -9    -9    1.16

Code: [Select]
R    G    B    K    B/A    G/M    BB
1443    845    2606    3816    -9    9    3.08
1803    1181    1570    6172    6    -9    1.33

Another interesting value:
Code: [Select]
R    G    B    K    B/A    G/M    RB
1978    989    1781    5994    5    3    2


Re: Decoding White Balance
« Reply #5 on: 21 / August / 2016, 21:09:53 »
New record, from Tungsten as base
Code: [Select]
R    G    B    K    B/A    G/M    BB
837 684 2939 2643 -9 0 4.29678362573099
« Last Edit: 21 / August / 2016, 21:12:16 by jmac698 »

Re: Decoding White Balance
« Reply #6 on: 27 / January / 2017, 06:44:21 »
I'm back!
Just want to clarify that the script goes g9b9 (I call this -9, -9), g9b8 (-9,-8)...g9a9 (-9,9) then b8g9 (-8,-9).. etc. That means it starts at the left, goes from top to bottom, then moves right.

My battery died, I finally got a replacement and now this is the first script I'm running, to finish my table of modified WB values.

I should warn you that cheap batteries don't nearly have the same capacity. I'm hoping it can finish 361 shots.

 

Related Topics