RGB/XYZ Matrices

Given the chromaticity coordinates of an RGB system (xr, yr), (xg, yg) and (xb, yb) and its reference white (XW, YW, ZW), here is the method to compute the 3 × 3 matrix for converting RGB to XYZ:

Equation 1

where

Equation 2

Implementation Notes:

  1. In order to properly use this matrix, the RGB values must be linear and in the nominal range [0.0, 1.0]. In many cases, RGB values may first need conversion (for example, dividing by 255 and then raising them to a power).
  2. Be careful that reference whites are used consistently. For example, sRGB is defined relative to a D65 reference white and ICC profiles are defined relative to a D50 reference white. Mismatched reference whites must be accounted for elsewhere, typically by using a chromatic adaptation algorithm.
  3. The inverse matrix (i.e. the matrix converting XYZ to RGB) is computed by inverting matrix [M] above.

Some Common RGB Working Space Matrices

Using the chromaticities and reference whites of common RGB working spaces, I have done the math for you to compute the RGB-to-XYZ and XYZ-to-RGB matrices. Note that these matrices are given relative to their own reference whites. If you examine the matrices for these working spaces found inside ICC profiles (through the redColorantTag, greenColorantTag and blueColorantTag), those matrices will always be relative to D50, and therefore, the colorants have been subjected to a chromatic adaptation transformation if the working space reference white is not also D50.

RGB Working Space Reference White RGB to XYZ [M] XYZ to RGB [M]-1
Adobe RGB (1998) D65
 0.576700    0.297361    0.0270328  
0.185556 0.627355 0.0706879
0.188212 0.0752847 0.991248
 2.04148    -0.969258    0.0134455  
-0.564977 1.87599 -0.118373
-0.344713 0.0415557 1.01527
Apple RGB D65
 0.449695    0.244634    0.0251829  
0.316251 0.672034 0.141184
0.18452 0.0833318 0.922602
 2.95176    -1.0851      0.0854804  
-1.28951 1.99084 -0.269456
-0.47388 0.0372023 1.09113
BestRGB D50
 0.632670    0.228457    0.000000   
0.204556 0.737352 0.00951424
0.126995 0.0341908 0.815696
 1.75526    -0.544134    0.00634681 
-0.483679 1.50688 -0.0175762
-0.253000 0.0215528 1.22570
Beta RGB D50
 0.671254    0.303273    0.000000   
0.174583 0.663786 0.040701
0.118383 0.0329413 0.784509
 1.68323    -0.771023    0.0400012 
-0.428236 1.70656 -0.0885376
-0.236018 0.0446899 1.27236
BruceRGB D65
 0.467384    0.240995    0.0219086  
0.294454 0.683554 0.0736135
0.188629 0.0754517 0.993447
 2.74566    -0.969257    0.0112707  
-1.13589 1.87599 -0.113959
-0.435057 0.0415557 1.01311
CIE E
 0.488718    0.176204    0.000000   
0.310680 0.812985 0.0102048
0.200602 0.0108109 0.989795
 2.37067    -0.513885    0.00529818 
-0.900040 1.42530 -0.0146949
-0.470634 0.0885814 1.00940
ColorMatch D50
 0.509344    0.274884    0.0242545  
0.320907 0.658132 0.108782
0.133969 0.0669845 0.692174
 2.64229    -1.11198     0.0821698  
-1.22343 2.05902 -0.280725
-0.393014 0.0159614 1.45599
DonRGB4 D50
 0.645771    0.278350    0.00371134 
0.193351 0.687970 0.0179862
0.125098 0.0336802 0.803513
 1.76039    -0.712629    0.00782072 
-0.488120 1.65274 -0.0347411
-0.253613 0.0416715 1.24477
ECI D50
 0.650204    0.320250    0.000000   
0.178077 0.602071 0.0678390
0.135938 0.0776791 0.757371
 1.78276   -0.959362    0.0859318   
-0.496985 1.94780 -0.174467
-0.269010 -0.0275807 1.32283
Ekta Space PS5 D50
 0.593891    0.260629    0.000000   
0.272980 0.734946 0.0419970
0.0973486 0.00442493 0.783213
 2.00438    -0.711029    0.0381263  
-0.730484 1.62021 -0.0868780
-0.245005 0.0792227 1.27254
NTSC C
 0.606734    0.298839    0.000000   
0.173564 0.586811 0.0661196
0.200112 0.114350 1.11491
 1.91049    -0.984310    0.0583744  
-0.532592 1.99845 -0.118518
-0.288284 -0.0282980 0.898611
PAL / SECAM D65
 0.430587    0.222021    0.0201837  
0.341545 0.706645 0.129551
0.178336 0.0713342 0.939234
 3.06313    -0.969258    0.0678674  
-1.39328 1.87599 -0.228821
-0.475788 0.0415557 1.06919
ProPhoto D50
 0.797675    0.288040    0.000000   
0.135192 0.711874 0.000000
0.0313534 0.000086 0.825210
 1.34594    -0.544599    0.000000   
-0.255608 1.50817 0.000000
-0.0511118 0.0205351 1.21181
SMPTE-C D65
 0.393555    0.212395    0.0187407  
0.365253 0.701049 0.111932
0.191659 0.0865558 0.958297
 3.50570    -1.06906     0.0563117  
-1.73964 1.97781 -0.196994
-0.544011 0.0351720 1.05005
sRGB D65
 0.412424    0.212656    0.0193324  
0.357579 0.715158 0.119193
0.180464 0.0721856 0.950444
 3.24071    -0.969258    0.0556352  
-1.53726 1.87599 -0.203996
-0.498571 0.0415557 1.05707
WideGamut D50
 0.716105    0.258187    0.000000   
0.100930 0.724938 0.0517813
0.147186 0.0168748 0.773429
 1.46281    -0.521793    0.0349342  
-0.184062 1.44724 -0.0968931
-0.274361 0.0677228 1.28841