CIE 1931 XYZ Color Space
Introduction
In previous tutorials we have been using various RGB color spaces. You even get to construct one yourself. One slight issue with RGB color spaces is that there are many of them, each of which depends on what you mean by R, G, and B primaries (and of course the reference white). In addition, as discussed in the chromaticity tutorial, there inevitable are going to be colors that can be "produced" only using negative amount of the primaries, no matter what the RGB primaries you choose. While that's mathematically and physically rigorous, it's not quite intuitive. So CIE in 1931 wanted to standardize a color space that 1) can be used as a "common language" (without having to laboriously specify what the primaries are every time you say RGB space) and that 2) all human visible colors are produced by mixing non-negative amount of the primaries. That color space is called the CIE 1931 XYZ color space, sometimes referred to simply as the XYZ color space.
This tutorial explores the intuition behind the XYZ color space, and how it is constructed from the CIE 1931 RGB color space. Before we get started, you might be wondering isn't the LMS cone space a color space that satisfies the two conditions above? It's standard, since it's tied to inherent human color perception (insofar as the "Standard Observers" are concerned). It's also a color space where all colors are expressed using positive amounts of the primaries (cone responses). These are all true, but the LMS cone sensitivies were not reliably available back in 1931. It was not until fairly recently were the cone sensitivies experimentally measured using microspectrophotometry or suction electrode from surgically removed cone cells or through psychophysics on individuals with color deficiencies. See our lecture on photoreceptors for a detailed discussion.
Part 1: The Intuition
We will show what the transformation does and leave the derivation of the transformation to the next part. The left plot shows the spectral locus in the CIE 1931 RGB color space. Spin around the plot and hover the locus you will see that some spectral lights require negative amount of primaries. One goal of the XYZ space is that all spectral colors should have positive primary amounts. In other words, the spectral locus should reside in the all-positive octant of the XYZ space.
One way to reason about the RGB to XYZ transformation is to choose three vectors originating from the origin in the RGB space ($\overrightarrow{\mathbf{ON_r}}$, $\overrightarrow{\mathbf{ON_g}}$, and $\overrightarrow{\mathbf{ON_b}}$); these vectors should be chosen in such a way that they, after transformation, become the basis vectors in the XYZ space. In the RGB space, the spectral locus should be completely enclosed by the planes formed by the three vectors. Toggle the "Show Bounds" button to reveal the vectors and the bound.
Now click the "XYZ" button. You will see the transformed locus in the XYZ space. The three vectors are now the unit basis vectors in the XYZ space, and the spectral locus is completely within the all-positive octant in the XYZ space.
$N_r, N_g, N_b$ in RGB space are mapped to the $C_r, C_g, C_b$ points in the rg-chromaticity diagram. Along with the RGB to XYZ transformation, there is also a corresponding rg to xy chromaticity transformation on $C_r, C_g, C_b$, which we visualize in the plot on the right. Toggle the "xy-chromaticity" button to see the transformation. The chromaticity gamut of the XYZ space is the triangle, which completely encloses the spectral locus. The HVS gamut (in chromaticity) is the area under the spectral locus. Note, however, while RGB-to-XYZ is a linear transformation, rg-to-xy transformation is not. This is because RGB-to-rgb is not linear, as discussed in the chromaticity tutorial.
Part 2: The Math
The actual process of deriving the transformation is a bit messy. Fairman et al. has a detailed paper (erratum) describing the intricacies of the derivation with many interesting historical notes that are definitely worth reading. We will simplify a few minor details and present the main steps in deriving the transformation matrix.
The goal is to obtain a transformation $T$ that converts every $RGB$ triplet to an $XYZ$ triplet by:
$ \begin{bmatrix} X \\ Y \\ Z \end{bmatrix} = \begin{bmatrix} T_{00} & T_{01} & T_{02} \\ T_{10} & T_{11} & T_{12} \\ T_{20} & T_{21} & T_{22} \end{bmatrix} \times \begin{bmatrix} R \\ G \\ B \end{bmatrix}, $
There are nine unknowns in matrix $T$. We will need to somehow come up with nine equations to solve for them. Of course, technically nothing prevents us from writing an arbitrary matrix and use it as the transformation matrix. However, CIE 1931 imposed various requirements that will lead to a unique transformation matrix. We will dissect the requirements step by step.
Step 1: From 9 Unknowns to 6 Unknowns
The transformation matrix, when applied to spectral lights, essentially transforms the RGB Color Matching Functions (CMFs) to the corresponding XYZ CMFs:
$ \begin{bmatrix} X_{380} & \cdots & X_{500} & \cdots & X_{780} \\ Y_{380} & \cdots & Y_{500} & \cdots & Y_{780} \\ Z_{380} & \cdots & Z_{500} & \cdots & Z_{780} \end{bmatrix} = \begin{bmatrix} T_{00} & T_{01} & T_{02} \\ T_{10} & T_{11} & T_{12} \\ T_{20} & T_{21} & T_{22} \end{bmatrix} \times \begin{bmatrix} R_{380} & \cdots & R_{500} & \cdots & R_{780} \\ G_{380} & \cdots & G_{500} & \cdots & G_{780} \\ B_{380} & \cdots & B_{500} & \cdots & B_{780} \end{bmatrix}, $
CIE 1931 required that the Y CMF should exactly match the photopic luminous efficiency function $V(\lambda)$ as defined in the CIE 1924 standard, which documents $V(\lambda)$ wavelength by wavelength. That is:
$ \begin{bmatrix} V_{380} & \cdots & V_{500} & \cdots & V_{780} \end{bmatrix} = \begin{bmatrix} Y_{380} & \cdots & Y_{500} & \cdots & Y_{780} \end{bmatrix} = \begin{bmatrix} T_{10} & T_{11} & T_{12} \end{bmatrix} \times \begin{bmatrix} R_{380} & \cdots & R_{500} & \cdots & R_{780} \\ G_{380} & \cdots & G_{500} & \cdots & G_{780} \\ B_{380} & \cdots & B_{500} & \cdots & B_{780} \end{bmatrix}, $
This is an over-determined system, with 3 unknowns but many more equations. So generally we would have to estimate a best-fit. But in this case, there actually is a perfect fit, at least theoretically. In theory, the RGB CMFs are a linear transformation away from the LMS cone fundamentals as discussed in this tutorial, and the luminous efficiency function is, in theory, also a linear transformation from the LMS cone fundamentals. So if the RGB CMFs and the luminous efficiency function are derived from the same set of data, the transformation is exact. In this particular case, the CIE 1931 RGB CMFs are constructed as a linear transformation from the CIE 1924 luminous efficiency function (see discussions here and here). As a result, $[T_{10}, T_{11}, T_{12}]$ is exactly calculated: $T_{10} = 1.0000, T_{11} = 4.5907, T_{12} = 0.0601$.
Step 2: From 6 Unknowns to 4 Unknowns
CIE 1931 required that the reference white in the XYZ space should be the same as that in the CIE 1931 RGB space (the exact reference white used is irrelavent, but it happens to be Equal-Energy White). As a result, $[1, 1, 1]$ in the RGB space should be mapped to $[K, K, K]$ in the XYZ space, where $K$ is a constant, indicating that white is represented by equal amount of the XYZ primaries. What this means is that the sums of each row in matrix $T$ should be same, and we know the sum of the second row, because the three elements in the second row are calculated in the previous step already. That is:
$T_{00} + T_{01} + T_{02} = T_{20} + T_{21} + T_{22} = 1.0000 + 4.5907 + 0.0601 = 5.6508$.
This allows us to reduce the matrix to just 4 unknowns:
\begin{bmatrix} 5.6508 - T_{01} - T_{02} && T_{01} && T_{02} \\ 1.0000 && 4.5907 && 0.0601 \\ 5.6508 - T_{21} - T_{22} && T_{21} && T_{22} \end{bmatrix}
Step 3: Solving For the 4 Unknowns
CIE 1931 also required that the XYZ CMFs are non-negative across the spectrum. This is equivalent to picking a triangle (with the vertices $C_r, C_g, C_b$) in the rg-chromaticity diagram that circumscribes the spectral locus. This triangle will be transformed to be the $[1, 0], [0, 0], [0, 1]$ triangle in the xy-chromaticity diagram. It was also preferred that that the locus fills the triangle as much as possible. There are many such triangles, and the exact choice is somewhat arbitrary. In the end the choices are: $C_r = [1.2749, -0.2777, 0.0028]$, $C_g = [-1.7400, 2.7677, -0.0277]$, and $C_b = [-0.7430, 0.1408, 1.6022]$. Precisely speaking, the choices of $C_r$ and $C_b$ are not completely arbitrary, the reason of which will become clear soon. But overall, the choice of the triangle had quite a bit of flexibility, and the XYZ space could have been quite different if a different triangle had been chosen. Now let's see how we use this triangle to solve for the remaining four unknowns.
Using the $C_g$ coordinates, we have:
$ \begin{bmatrix} 5.6508 - T_{01} - T_{02} && T_{01} && T_{02} \\ 1.0000 && 4.5907 && 0.0601 \\ 5.6508 - T_{21} - T_{22} && T_{21} && T_{22} \end{bmatrix} \times \begin{bmatrix} -1.7400k \\ 2.7677k \\ -0.027k \end{bmatrix} = \begin{bmatrix} 0 \\ C \\ 0 \end{bmatrix} $
where $k$ is a constant that converts a $rgb$ chromaticity to a $RGB$ triplet (remember, we want to derive a RGB-to-XYZ matrix, not a rgb-to-xyz matrix), and $C$ is a non-zero constant indicating that $C_g$ will be converted to a $XYZ$ triplet where only the $Y$ value is non-zero (the actual value of $C$ is related to $k$ and is not important here).
We know $k$ can't be zero, since $C$ is definitely not zero. Therefore, we have:
$ \begin{bmatrix} 5.6508 - T_{01} - T_{02} && T_{01} && T_{02} \\ 5.6508 - T_{21} - T_{22} && T_{21} && T_{22} \end{bmatrix} \times \begin{bmatrix} -1.7400 \\ 2.7677 \\ -0.027 \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \end{bmatrix} \label{a}\tag{1} $
Similarly, using the $C_b$ coordinates we have:
$ \begin{bmatrix} 5.6508 - T_{01} - T_{02} && T_{01} && T_{02} \\ 1.0000 && 4.5907 && 0.0601 \\ 5.6508 - T_{21} - T_{22} && T_{21} && T_{22} \end{bmatrix} \times \begin{bmatrix} -0.7430k \\ 0.1408k \\ 1.6022k \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \\ C \end{bmatrix} $, where $k$ and $C$ are again constants, but their values are not the same as in the $C_g$ case.
Here you can see that the choice of $C_b$ can't be arbitrary, because we must satify $[1.0000, 4.5907, 0.0601] \times [−0.7430, 0.1408, 1.6022]^T = 0$
We can't really say anything about $T_{21}$ and $T_{22}$, because we don't know what $C$ is, but we definitely can make use of the first row leveraging that $k$ must be non-zero:
$ \begin{bmatrix} 5.6508 - T_{01} - T_{02} && T_{01} && T_{02} \end{bmatrix} \times \begin{bmatrix} -0.7430 \\ 0.1408 \\ 1.6022 \end{bmatrix} = \begin{bmatrix} 0 \end{bmatrix} \label{b}\tag{2} $
Now let's use the $C_r$ coordinates:
$ \begin{bmatrix} 5.6508 - T_{01} - T_{02} && T_{01} && T_{02} \\ 1.0000 && 4.5907 && 0.0601 \\ 5.6508 - T_{21} - T_{22} && T_{21} && T_{22} \end{bmatrix} \times \begin{bmatrix} 1.2749k \\ -0.2777k \\ 0.0028k \end{bmatrix} = \begin{bmatrix} C \\ 0 \\ 0 \end{bmatrix} $.
Again you can see that the choice of $C_r$ can't be arbitrary, as it must hold that $[1.0000, 4.5907, 0.0601] \times [1.2749, -0.2777, 0.0028]^T = 0$
We can't use the first row, as $C$ is unknown, but we can use the last row:
$ \begin{bmatrix} 5.6508 - T_{21} - T_{22} && T_{21} && T_{22} \end{bmatrix} \times \begin{bmatrix} 1.2749 \\ -0.2777 \\ 0.0028 \end{bmatrix} = \begin{bmatrix} 0 \end{bmatrix} \label{c}\tag{3} $
Now given the Equations $\ref{a}$, $\ref{b}$, and $\ref{c}$, we can finally solve for the four unknowns.
Sometimes you will see that the $\overline{\mathbf{C_r C_b}}$ line is called the alychne, or the line of zero luminance. Here is the intuition. All the points along the $\overline{\mathbf{C_r C_b}}$ line will be transformed to sit on the x-axis in the xy-chromaticity diagram, where the y values are 0. y is proportional to Y, which is the same as the luminous efficiency function by construction. So points on the $\overline{\mathbf{C_r C_b}}$ line have zero luminance.
Here is another way to understand why the choices of $C_r$ and $C_b$ are not arbitrary. The second row of the matrix $T$ is calculated from the fact that the Y CMF must match the luminous efficiency function. As a result, we know that $[1.0000, 4.5907, 0.0601] \times [\mathbf{C_r}^T, \mathbf{C_b}^T] = [0, 0]$. That is, both $C_r$ and $C_b$ must sit on the $1.0000r + 4.5907g + 0.0601b = 0$ line.
Part 3: The xyY Color Space
Sometimes you will also see the notion of "xyY" space. That's nothing more than plotting a color using its xy chromaticity values and the Y value. Recall that from an xyz triplet of a color we can't uniquely reconstruct its XYZ value, since xyz contains just the ratio, but not the intensity information. Having the Y value helps recovers the intensity. Can we use xyX or xyZ? Yes, but the nice thing about Y is that Y, by construction, is the luminance of a light (under 1 unit radiance). In one figure, we get both the chromaticity information and the intensity information. It's convenient that way.