Color space conversion (2)  RGB-XYZ conversion


Conversion from RGB to XYZ

The CIE XYZ color space is widely used as a working space when converting sRGB and Adobe RGB color spaces to other color spaces. This section describes the conversion between the sRGB / Adobe RGB color space and the XYZ color space. sRGB and Adobe RGB color spaces are widely used for an RGB mode images in software such as Photoshop, and the color is specified with three components R, G, and B. For the RGB mode image, the color gamut becomes a cube (a so-called color cube, see Fig. 1) when R, G, and B are used as coordinate axes. Here, we assume that the minimum value of the component is 0, and the maximum value is 1.

RGB color cube gamma corrections for sRGB / Adobe RGB
Fig. 1.   RGB color space (sRGB / Adobe RGB) Fig. 2.   Tone correction for sRGB (blue) and
the gamma correction for Adobe RGB (red).

By the way, the RGB values ​​of sRGB / Adobe RGB have been corrected so that images look natural on the screen. Fig. 2 shows the tone correction curve, where  R, G, B  are the original values ​​proportional (linear) to the brightness, and  R', G', B'  are the corrected values. This curve is sometimes called the transfer function. The values of an RGB mode image are these  R', G', B'  values after correction. The tone correction can be expressed by the following equations:

For sRGB,
R' = { 12.92 R  (R ≤ 0.0031308)
1.055 R1/2.4 - 0.055  
 (R > 0.0031308)
(1)

For Adobe RGB,
R' = { 32 R  (R ≤ 0.00174)
R1/2.2    
 (R > 0.00174)
(2)

Though only the equations for R component is shown, the other components are the same. Adobe RGB uses the gamma correction of γ=2.2. As can be seen in Fig. 2, the correction for sRGB is almost the same as the γ=2.2 gamma correction. In each correction, the curve is switched to a straight line near the origin, to avoid an infinite slope at zero. When converting RGB to XYZ, we have to perform the inverse gamma correction beforehand to return the screen R', G', B' to the original (linear) R, G, B, first:

For sRGB,
R = { R' / 12.92  (R' ≤ 0.040450)
[(R' + 0.055) / 1.055] 2.4   
 (R' > 0.040450)

For Adobe RGB,
R = { R' /32  (R' ≤ 0.0556)
R' 2.2      
 (R' > 0.0556)


Next, we will convert the linear R, G, B values to X, Y, Z. The color gamut in the XYZ color system is determined by the coordinates of the R , G , and B primary colors of the sRGB (or other color spaces) and the coordinates of the white point. Table 1 gives the coordinates of primary colors for sRGB, P3-D65, and Adobe RGB color spaces with the values of x, y, z. The white point for these color spaces is D65, i.e.   (xw, yw, zw) = (0.3127, 0.3290, 0.3583),   or   (Xw, Yw, Zw) = (0.95046, 1.0, 1.08906).

Table 1.   The white point and primary colors of some color spaces.
Color space
White point R
G
B
xr yr zr xg yg zg xb yb zb
sRGB / HDTV
D65 0.64 0.33 0.03 0.30 0.60 0.10 0.15 0.06 0.79
P3-D65 (Display P3)
D65 0.68 0.32 0.00 0.265 0.69 0.045 0.15 0.06 0.79
Adobe RGB
D65
0.64
0.33
0.03
0.21
0.71
0.08
0.15
0.06
0.79
NTSC RGB (SDTV)
C
0.67
0.33
0.00
0.21
0.71 0.08 0.14
0.08
0.78
CIE Lab
D50
-
-
-
-
-
-
-
-

The conversion from RGB to XYZ is given by a matrix determined from these values ​​ (see Computing RGB-XYZ conversion matrix). If we write this transformation (linear transformation) as


(
X )

( R
)
Y M
G
Z
B

then, transformation matrix M can be given as in table 2.

Table 2.   Transformation matrix from RGB to XYZ. The inverse matrix is also given.
Color space
M M -1
sRGB (D65)
 0.412391  0.357584  0.180481
0.212639 0.715169 0.072192
0.019331 0.119195 0.950532
 3.240970 -1.537383 -0.498611
-0.969244 1.875968 0.041555
0.055630 -0.203977 1.056972
P3-D65 (D65)
 0.486571  0.265668  0.198217
0.228975 0.691739 0.079287
0.000000 0.045113 1.043944
 2.493497 -0.931384 -0.402711
-0.829489 1.762664 0.023625
0.035846 -0.076172 0.956885
Adobe RGB (D65)
 0.576669  0.185558  0.188229
0.297345 0.627364 0.075291
0.027031 0.070689 0.991338
 2.041588 -0.565007 -0.344731
-0.969244 1.875968 0.041555
0.013444 -0.118362 1.015175
NTSC RGB (C)
 0.6069    0.1735    0.2003
0.2989 0.5866 0.1145
0.0000 0.0661 1.1162
 1.9100   -0.5325   -0.2882
-0.9846 1.9991 -0.0283
0.0583 -0.1184 0.8976

sRGB gamut in the XYZ space   P3-D65 gamut in the XYZ space   Adobe RGB gamut in the XYZ space
Fig. 3.   Color gamuts of sRGB (left), P3-D65 (center) and Adobe RGB (right) in the XYZ space.

Fig. 3 shows color gamuts of sRGB, P3-D65, and Adobe RGB in the XYZ color space. We can see that the color gamut is parallelepiped in general. The sRGB, P3-D65, and Adobe RGB color gamuts are shown below in a three-dimensional XYZ color space along with the optimal color solid (GIF animation).

Conversion from XYZ to RGB

Conversion from the CIE XYZ color space to the RGB color space can be performed by the linear transformation using the inverse matrix:

( R )
( X )
G M -1 Y
B
Z

The resulting RGB ​​ have linear values (proportional to the original brightness). In order to obtain the values ​​for an RGB mode image, the tone correction such as gamma correction must be applied. Equation (1) should be used for sRGB, and equation (2) for Adobe RGB. Values of R', G', B' obtained in this way are the RGB values ​​of a usual RGB mode image.
Similar conversion seems to be performed in cameras and scanners. Three primary color data obtained by decomposing the light with color filters of a camera or a scanner will be converted into CIE XYZ values, converted into RGB, and then applied gamma correction if required for the image data format.



Back to the contents   Previous   Next
T. Fujiwara, 2011/12, 2019/09