I am writing code for some color conversion work and have a confusion. My purpose for this conversion is to get the colors look reasonably correct in a typical non-professional display (PC, tablet etc) when I save as png or jpeg for example.

Here are my steps:

  • I utilize a color calibration target (ISA ColorChecker) with reference values provided by the manufacturer in Lab space with D50 white point.
  • I capture a raw image of the target and demosaic the Bayer pattern arriving at RawRGB values for each of the Calibration Target's patches (average value is taken). To calculate a color correction matrix, I want to find the (not-gamma-corrected) sRGB values starting from the Lab reference values of the Target.
  • I use the formulas in http://www.brucelindbloom.com. First step is going from Lab to XYZ I use the D50 white reference point XYZReference = 0.9642,1.0000,0.8251
  • Second step is going from XYZ to sRGB and this is where the confusion is: I arrived at the XYZ values using a D50 white point, but sRGB with D65 illuminant is the most common working color space of consumer displays. Which of the inverseM matrices shall I be using to get this right?

After the linear conversion above, I know that I must also apply the gamma-companding.

Thank you!

  • What makes you think the sRGB standard uses D65? Whether one uses D50 or D65 (both are sRGB compliant) should be based in the expected display conditions. If ambient light is D50, then the display should use D50. If the ambient light is D65, then the display should use D65. Photographers have traditionally used D50 because print viewing booths use D50 lighting. More recently graphic designers tend to prefer D65 because the manufacturers of many mobile devices feel their devices look brighter and sell better if they output at D65, regardless of actual viewing conditions. – Michael C Mar 30 at 9:36
  • Yes, I am targeting "correct colors" (as good as it gets) in a typical consumer display without additional color calibration or professional setup by the user. I updated the question to make that clearer. Thank you! – bekoch Mar 30 at 10:23
  • The point is that just because a device is set to output at D65 doesn't mean the viewer will "see" (i.e. perceive) correct colors when using the device in, say, a tungsten lighting environment (or a 2700K CFL lit environment). If a neutral grey signal of, say, [128,128,128] is sent to a D65 screen and viewed under much warmer lighting, the viewer will perceive a decidedly blue cast in the "neutral" grey color on the screen. – Michael C Mar 30 at 16:37
  • "First step is going from Lab to XYZ I use the D50 white reference point XYZReference = 0.9504,1.0000,1.0888" No, it's not. "0.9504,1.0000,1.0888" is the D65 White Point. – doug Mar 31 at 18:21
  • thanks @doug, I corrected the mistake. – bekoch Apr 1 at 10:46

Which of the inverseM matrices shall I be using to get this right?

Use the sRGB, Bradford adapted inversion matrix: XYZ to RGB [M]-1

3.1338561 -1.6168667 -0.4906146
-.9787684  1.9161415  0.0334540
0.0719453 -0.2289914  1.4052427

This is used because everything involved in converting from/to L*a*b* and sRGB uses D50 even though D65 is the presumed display's white point. ICC profiles use D50 as the common reference white and primary chromaticity values in the ICC profiles are already adapted to D50. So D65 can be ignored.

Using L*a*b* 50 for the middle gray Colorchecker(tm) square, Conversion to XYZ should yield: XYZ=(0.177596 0.184187 0.151993) which is about 18% of D50 white.

Multiplying the inverting matrix M, with XYZ yields the sRGB value in linear gamma: RGB=(.184,.184,.184) which is expected. Note R=G=B and they are just above 18% reflectance which is L*50.

A good crosscheck is the BruceLindbloom calculator as shown here. Note gamma has been changed from sRGB's standard, modified 2.2 gamma to 1.0. If you wish to save the RGB values properly the sRGB gamma should be applied. You can also use the calculator to check your gamma algorithm if you pursue doing this.

enter image description here

  • Yes, thank you @doug. – bekoch Apr 2 at 8:52
  • And to be sure I also compared the two XYZ to RGB M^{-1} matrices for D65 and D50: the D50 is numerically equivalent to first applying a XYZD50 to XYZD65 Bradford chromatic adaptation matrix, and then using the D65 M^{-1} matrix. – bekoch Apr 2 at 8:58
  • @bekoch Yep. The theory is that human vision adapts to D65 when the sRGB (or, for instance, Adobe RGB which is also D65 for display) image is displayed. I prefer setting the display at D50 as it's a better match to a side-by-side print illuminated with D50. Calculations are the same which makes life easier. – doug Apr 2 at 13:50

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.