I want to know about the mathematics behind white balance. I understand that it should be 3 different constants being applied to the red/green/blue channels. Thus I used img1 as the original image and img2 as the balanced image (used RGBColor[.1, 0.4, 0.5] as the white color and picked line 100 as the sample line to allow faster calculation):-

img1 = ExampleData[{"TestImage", "Girl"}]
img2 = ColorBalance[img1, RGBColor[.1, 0.4, 0.5]]

line = 100;
data1 = (ImageData@img1)[[line, All]];
data2 = (ImageData@img2)[[line, All]];

data3 = data2/data1;

In fact, data3 fluctuated around {1.4, 0.8, 0.6} and {1.2, 0.7, 0.5}. I took the average and then Mean@data3 gives me {1.35116, 0.828725, 0.591499} as the output.

My question is, how does this {1.35116, 0.828725, 0.591499} related to RGBColor[.1, 0.4, 0.5] mathematically? I just want a rough formulae and an approximation with error is good enough. I tested different RGBColor color (I focused on the RGB values which give a sum of 1), but still can't find the relationship between the two. Wikipedia gives a formula, but I don't think that is applicable to this case.

Many thanks!

  • $\begingroup$ Read the documentation of ColorBalance: "With a given {temperature, tint} pair, ... [not your case]. Otherwise, Method->"LMSScaling" is used". And that scales in the LMS color space. For the equations, see the Wikipedia article you linked. $\endgroup$ – Lukas Lang Jul 29 '18 at 21:26
  • $\begingroup$ Thanks. I got a closed approximation by img2 = ColorBalance[img1, RGBColor[.3, 0.4, 0.5], Method -> "RGBScaling"], and then reciprocal. $\endgroup$ – H42 Jul 31 '18 at 1:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.