Skip to content
Part IA Michaelmas Term

Colour Space Transformations

Linear Transformations

Converting between linear RGB spaces is a matrix operation:

[XYZ]=MRGBXYZ[RGB]\begin{bmatrix} X \\ Y \\ Z \end{bmatrix} = \mathbf{M}_{\text{RGB}\to\text{XYZ}} \begin{bmatrix} R \\ G \\ B \end{bmatrix}

RGB to XYZ Matrix

For sRGB (ITU-R 709 primaries):

M709XYZ=[0.41240.35760.18050.21260.71520.07220.01930.11920.9505]\mathbf{M}_{\text{709}\to\text{XYZ}} = \begin{bmatrix} 0.4124 & 0.3576 & 0.1805 \\ 0.2126 & 0.7152 & 0.0722 \\ 0.0193 & 0.1192 & 0.9505 \end{bmatrix}

RGB → XYZ → RGB conversion path

Between RGB Spaces

To convert from sRGB to Rec. 2020:

[R2020G2020B2020]=MXYZ2020M709XYZ[R709G709B709]\begin{bmatrix} R_{2020} \\ G_{2020} \\ B_{2020} \end{bmatrix} = \mathbf{M}_{\text{XYZ}\to\text{2020}} \cdot \mathbf{M}_{\text{709}\to\text{XYZ}} \begin{bmatrix} R_{709} \\ G_{709} \\ B_{709} \end{bmatrix}

Steps

  1. Linearise: Remove gamma encoding
  2. Convert to XYZ: Apply MRGBXYZ\mathbf{M}_{\text{RGB}\to\text{XYZ}}
  3. Convert to target: Apply MXYZRGB1\mathbf{M}_{\text{XYZ}\to\text{RGB}}^{-1}
  4. Re-encode: Apply target gamma

Computing RGB to XYZ Matrix

Given primaries (xR,yR)(x_R, y_R), (xG,yG)(x_G, y_G), (xB,yB)(x_B, y_B) and white point (xW,yW)(x_W, y_W):

Step 1: Form Primary Matrix

P=[xR/yRxG/yGxB/yB111(1xRyR)/yR(1xGyG)/yG(1xByB)/yB]\mathbf{P} = \begin{bmatrix} x_R/y_R & x_G/y_G & x_B/y_B \\ 1 & 1 & 1 \\ (1-x_R-y_R)/y_R & (1-x_G-y_G)/y_G & (1-x_B-y_B)/y_B \end{bmatrix}

Step 2: Solve for Scaling Factors

[SRSGSB]=P1[xW/yW1(1xWyW)/yW]\begin{bmatrix} S_R \\ S_G \\ S_B \end{bmatrix} = \mathbf{P}^{-1} \begin{bmatrix} x_W/y_W \\ 1 \\ (1-x_W-y_W)/y_W \end{bmatrix}

Step 3: Construct Transform

MRGBXYZ=[SRxR/yRSGxG/yGSBxB/yBSRSGSBSR(1xRyR)/yRSG(1xGyG)/yGSB(1xByB)/yB]\mathbf{M}_{\text{RGB}\to\text{XYZ}} = \begin{bmatrix} S_R x_R/y_R & S_G x_G/y_G & S_B x_B/y_B \\ S_R & S_G & S_B \\ S_R(1-x_R-y_R)/y_R & S_G(1-x_G-y_G)/y_G & S_B(1-x_B-y_B)/y_B \end{bmatrix}

Mapping to a Display with Custom Primaries

Given:

  • Target spectrum L\mathbf{L}
  • Display primary spectra PRGB\mathbf{P}_{\text{RGB}} (N×3 matrix)
  • CIE XYZ matching functions SXYZ\mathbf{S}_{\text{XYZ}} (N×3 matrix)

Algorithm

  1. Find XYZ of target:

CXYZ=SXYZL=[XYZ]\mathbf{C}_{\text{XYZ}} = \mathbf{S}_{\text{XYZ}}^\top \mathbf{L} = \begin{bmatrix} X \\ Y \\ Z \end{bmatrix}

  1. Construct primary matrix:

MRGBXYZ=SXYZPRGB\mathbf{M}_{\text{RGB}\to\text{XYZ}} = \mathbf{S}_{\text{XYZ}}^\top \mathbf{P}_{\text{RGB}}

  1. Solve for RGB:

[RGB]=MRGBXYZ1CXYZ\begin{bmatrix} R \\ G \\ B \end{bmatrix} = \mathbf{M}_{\text{RGB}\to\text{XYZ}}^{-1} \mathbf{C}_{\text{XYZ}}

  1. Apply display encoding:

[RGB]=[R1/γG1/γB1/γ]\begin{bmatrix} R' \\ G' \\ B' \end{bmatrix} = \begin{bmatrix} R^{1/\gamma} \\ G^{1/\gamma} \\ B^{1/\gamma} \end{bmatrix}

Luma Formula

Luma (display-encoded luminance approximation):

Y=0.2126R+0.7152G+0.0722BY' = 0.2126 R' + 0.7152 G' + 0.0722 B'

Important Note

Luma ≠ Luminance:

  • Luma uses gamma-corrected (display-encoded) values
  • Luminance uses linear values
  • Luma is an approximation for video processing

Gamut Mapping

When converting between spaces with different gamuts:

SituationAction
Colour inside both gamutsDirect mapping
Colour outside destinationGamut mapping required

Gamut Mapping Strategies

StrategyDescription
ClippingClip to nearest in-gamut colour
CompressionReduce saturation proportionally
PerceptualPreserve relationships, compress into gamut

Summary

  • Linear RGB to XYZ conversion uses 3×3 matrices
  • Transform between RGB spaces via XYZ intermediate
  • Matrix derivation requires primaries and white point
  • Luma approximates luminance from gamma-encoded values

Past Paper Questions

2024 Paper 3 Question 4: How would you convert a colour from sRGB to Rec. 2020? What steps are involved?

2023 Paper 3 Question 4: Derive the RGB to XYZ transformation matrix given the primaries and white point.

2022 Paper 3 Question 3: What is the difference between luma and luminance?