Chromaticity Matrix to Tristimulus Matrix Conversion for RGB Color Spaces – Even In the Dark

Two methods to transform primary chromaticities and white point into primary tristimulus values are examined and compared. One method appears in numerous places in the literature; we refer to this as the “familiar” method, and provide a novel interpretation of it. The second is much less well-known and is referred to as the “unfamiliar” method. Necessary and sufficient conditions for computing primary tristimulus values from their chromaticities are identified; in brief, the triangle in the (x , y) chromaticity diagram must have non-zero area. The computational burdens for the methods were compared; the familiar method required slightly more arithmetical operations. Two problems with the familiar method were identified: high potential for rounding error and the inability to contend with a non-luminous primary. The unfamiliar method is less prone to rounding error, and is able to contend with primaries on the alychne. It is recommended that the unfamiliar method be preferred. Symbols and Notation R, G, B: Radiometrically-linear red, green, and blue X , Y, Z : (CIE) tristimulus values Xn, Yn, Zn: Tristimulus values of color space’s white point XR, YR, ZR: Tristimulus values of color space’s red primary XG , YG , ZG ; XB , YB , ZB : Tristimulus values of color space’s green and blue primaries, respectively xR, yR, zR: Chromaticity coordinates of red primary xG , yG , zG ; xB , yB , zB : Chromaticity coordinates of green and blue primaries, respectively T: Matrix containing the tristimulus values of the primaries T̃: Matrix of tristimulus values of primaries, with each primary normalized to unit luminance C: Matrix containing the chromaticity coordinates of the primaries SR: Tristimulus sum for red primary (SR = XR+YR+ ZR) SG , SB : Tristimulus sums for green and blue primaries, respectively S: Matrix containing SR, SG , and SB on diagonal, zero elsewhere Some nomenclature This paper compares two methods for computing the tristimulus values of three primaries of specified chromaticity coordinates that result in a specified white point. That phrase, while accurate, is cumbersome. We shall simply refer to “the tristimulus values of the primaries” in the remainder of the paper. Introduction In certain color spaces, including sRGB, primaries are specified in terms of their chromaticity coordinates, together with the tristimulus values of a white point. [1, 2] Some image storage formats, including the Portable Network Graphic (PNG) format, offer the capability of similar specification of the chromaticity coordinates of the primaries in image metadata. [3] Knowing the primaries permits color management, interchange of data, and greater inter-operability. These benefits stem from the ability to transform from RGB into a common color space such as CIE XYZ. Stable-primary RGB color spaces and their primaries In color spaces such as sRGB, Adobe 1998 RGB, and DCI-P3, the tristimulus values produced are linearly related to the relative radiometric amplitudes of each primary, with the linear relation governed by the tristimulus values of each primary. A color space with this property is characterized as having stable primaries. [4] The discussion in this paper applies to stable-primary RGB color spaces whose primaries are defined by their chromaticity coordinates, together with the tristimulus values of the white point. It is possible to define the primaries of a stable-primary RGB color space in terms of their tristimulus values. However, because tristimulus values vary with white point luminance and chromaticity, and the physical means of producing color, such as phosphors, filters, organic light-emitting diodes or lasers are more directly tied to the chromaticity coordinates, it is customary to specify the primaries in terms of their chromaticity coordinates (which are, in theory, invariant with respect to changes in white point). Nevertheless, it is their tristimulus values, rather than their chromaticity coordinates, that are ultimately required for color management and related tasks. Conversion input and output The goal is to start with a white point and the chromaticity coordinates of the primaries, and determine the tristimulus values of the primaries needed to produce the specified white point. The tristimIS&T International Symposium on Electronic Imaging 2018 Color Imaging XXIII: Displaying, Processing, Hardcopy, and Applications 324-1 https://doi.org/10.2352/ISSN.2470-1173.2018.16.COLOR-324 This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/


Introduction
In certain color spaces, including sRGB, primaries are specified in terms of their chromaticity coordinates, together with the tristimulus values of a white point. [1,2] Some image storage formats, including the Portable Network Graphic (PNG) format, offer the capability of similar specification of the chromaticity coordinates of the primaries in image metadata. [3] Knowing the primaries permits color management, interchange of data, and greater inter-operability. These benefits stem from the ability to transform from RGB into a common color space such as CIE XYZ.

Stable-primary RGB color spaces and their primaries
In color spaces such as sRGB, Adobe 1998 RGB, and DCI-P3, the tristimulus values produced are linearly related to the relative radiometric amplitudes of each primary, with the linear relation governed by the tristimulus values of each primary. A color space with this property is characterized as having stable primaries. [4] The discussion in this paper applies to stable-primary RGB color spaces whose primaries are defined by their chromaticity coordinates, together with the tristimulus values of the white point.
It is possible to define the primaries of a stable-primary RGB color space in terms of their tristimulus values. However, because tristimulus values vary with white point luminance and chromaticity, and the physical means of producing color, such as phosphors, filters, organic light-emitting diodes or lasers are more directly tied to the chromaticity coordinates, it is customary to specify the primaries in terms of their chromaticity coordinates (which are, in theory, invariant with respect to changes in white point). Nevertheless, it is their tristimulus values, rather than their chromaticity coordinates, that are ultimately required for color management and related tasks.

Conversion input and output
The goal is to start with a white point and the chromaticity coordinates of the primaries, and determine the tristimulus values of the primaries needed to produce the specified white point. The tristim- ulus values may be gathered into a matrix, thus: to facilitate conversion between radiometrically-linear primary amplitudes R, G, and B and tristimulus values X , Y , and Z using the matrix formula: as well as the inverse relationship, going from tristimulus values to primary amplitudes: The process of going from input to output, according to the two methods, will be addressed in sections that follow.

Statement of Problem
No method for direct conversion of the chromaticity coordinates of a set of three primaries into the corresponding tristimulus values needed to produce a specified white point seems to exist. Rather, there are at least two methods that each require determination of an intermediate result. One method appears in Bala [5] and Berns [4] and elsewhere. [6] Because it seems to appear in several sources, it is referred to in this paper as the "familiar method." The other is relatively obscure, appearing in Viggiano and Wang; [7] this method will be denoted the "unfamiliar method." Both methods will be described in more detail below.
This investigation addressed the following questions: 1. What are the necessary and sufficient conditions a set of three sets of chromaticity coordinates must satisfy to permit computation of the corresponding tristimulus values, once a white point is specified?
2. Must any additional conditions be satisfied to ensure the matrix of tristimulus values may be inverted, permitting conversion from XYZ to RGB?
3. Does either of the two methods impose any additional restrictions on the primaries?
4. Does one of the methods require less computational burden than the other?
5. Is one of the methods more susceptible to numerical errors, such as from rounding, than the other?

Necessary and sufficient conditions for the conversion
Assuming the white point is specified in terms of its tristimulus values, and three primaries are specified as a set of chromaticity coordinates, it is necessary that the three primaries enclose a triangle with non-zero area in the x,y chromaticity diagram. The area of the triangle may be computed as a determinant: (This may result in a negative area if the primaries R, G, and B trace a clockwise path in the chromaticity diagram, rather than a counterclockwise path as would normally be the case.) This is also a sufficient condition, as shall be demonstrated in the discussion on the unfamiliar method.

Example 2.
Consider the ITU-R BT.709 primaries, presented earlier and illustrated in Figure 1: We compute the area in the CIE x, y chromaticity diagram of the triangle whose vertices are the chro- Therefore, there exists a matrix of tristimulus values of primaries with these chromaticity coordinates that will produce, at least mathematically, any desired white point.

Example 3.
Consider three primaries whose chromaticity coordinates fall on the same line, as shown in Figure 2: These primaries, as a group, are not suitable because they do not enclose a triangle in the x, y chromaticity diagram.

Conditions to obtain inverse tristimulus matrix
The inverse of the matrix of primary tristimulus values is required for XYZ to RGB conversions, as indicated in Eq (2). Necessary and sufficient conditions for existence of the inverse matrix, T −1 , are: 1. The area of the triangle enclosed by the primaries in the x, y chromaticity diagram be non-zero, and 2. The chromaticity coordinates of the white point not fall on that triangle.
Further, if the color space is to be of practical use, the chromaticity coordinates of the white point should fall inside the triangle enclosed by the primaries.

The Familiar Method
A step-by-step description of the method is covered in the first four parts of this section. A fully-worked example follows. Computational burden and limitations of the method are discussed in the remaining parts of this section.

Preliminary steps
Because the chromaticity coordinates sum to unity, it is customary to specify only the x and y chromaticity coordinates of each primary. Nevertheless, the z chromaticity coordinates are needed; it is convenient to compute them at this point using standard colorimetric practice. Also, the tristimulus values of the white point must be available. If the white point is specified in terms of its chromaticity coordinates (x n , y n ) and luminance Y n , standard procedures are used to convert these into the tristimulus values X n , Y n , and Z n . If the white point's luminance is unknown, common practice is that it be assumed to be unity.

Conversion of chromaticities to tristimulus values with unit luminance
The chromaticity coordinates of each primary are divided by the y chromaticity coordinate of that primary, and the quotients arranged in a matrix, using the tilde above the T to indicate this is not the matrix of tristimulus values used in Eq (1): While one may wish to think of the first column ofT as the chromaticities of the red primary, relative to y R , and analogously for the second (green) and third (blue) columns, each column corresponds to the tristimulus values of the corresponding primary, normalized to unit luminance. This is why we selected the nomenclatureT, for matrix of modified tristimulus values.

Solve for luminance of each primary
The intermediate result, the luminance required for each primary to produce the specified white point, is now tackled. This is obtained as the solution to a system of three linear equations; stated with the result on the left-hand side and the knowns on the right of the equals though it is computationally more efficient to solve the corresponding linear system for the unknown luminances than it is to invertT and perform the vector multiplication.

Obtain remaining tristimulus values
At this point, one has the tristimulus values of each primary normalized to unit luminance, and the luminances for each primary necessary to produce the specified white point. The latter constitutes the middle row of the desired result, matrix T. The X (first row) and Z (third row) tristimulus values of each primary may be obtained by multiplication:

Example 4. Familiar method applied to BT.709
Preliminary steps. Compute the z chromaticity coordinates: BT.709 does not specify a specific whitepoint luminance, so we use Y n = 1, and compute:  Note: ± is sign change (negation).

Chromaticity coordinates to tristimulus values at unit luminancẽ
In the third step, it is assumed the inverse of the matrixT is com-

Limitations and disadvantages of the familiar method No primary on alychne
If a primary is located on the alychne, the set of stimuli with zero luminance, and, hence, have y = 0 in the chromaticity diagram, [8, page 139] it is not possible to determine its tristimulus values at unit luminance; the quotients x /y and z /y will not exist. Therefore, the familiar method will fail if any of primaries have zero luminance. It is speculated that this limitation drove the decision to use an extremely small non-zero value (0.0001) to be used for the y chromaticity of the blue primary in the RIMM and ROMM RGB color spaces. [9] A consequence of this limitation means that the familiar method is unable to provide transform the XYZ primaries back to themselves because two of the primaries were selected from the alychne. This can have practical consequences if, for example, a set of primaries, close to but not necessarily equal to the familiar X, Y, and Z, are to be selected using an algorithmic optimization process.

Tendency for rounding error
When the y chromaticity coordinate of a primary is close to zero, as is the case for the blue primary in RIMM/ROMM and Pro Photo RGB, the x and z chromaticity coordinates for that primary will be divided by a number close to zero. This introduces opportunity for numerical inaccuracy, particularly rounding error.

Theory of the unfamiliar method
As with the familiar method, an intermediate result is obtained in the unfamiliar method. However, the sum of the tristimulus values are determined for each primary, rather than the luminance of each primary.
One may write: These sums may be collected into a diagonal matrix for notational convenience: and so on, the matrix of tristimulus values of the primaries may be written: where C is the matrix of primaty chromaticities: Note the absence of the tilde on the T in Eq (7); this means this matrix contains the required tristimulus values for each primary, not the tristimulus values each normalized to unit luminance.

Assuming the white point is obtained when
As shall be demonstrated later, using these tristimulus sums as the intermediate result not only requires marginally fewer operations, but offers greater numerical accuracy and permits one or two of the primaries to be located on the alychne.

Using the Unfamiliar Method
The first three parts of this section describe the steps used in the unfamiliar method. In the remaining parts, a fully-worked example is presented, the computational burden is parsed by operation type, and a discussion of any additional constraints the method places on the primaries beyond the necessary conditions identified earlier.

Preliminary steps
As in the familiar method, the z chromaticity coordinate of each primary is computed, and the tristimulus values of the white point are computed from their chromaticity coordinates, if necessary. The chromaticity coordinates of the primaries are then gathered into the matrix C.

Solve for the tristimulus sums
The tristimulus sums S R , S G , and S B are obtained as the solution of a system of three linear equations, using the chromaticities of the phosphors directly. Write this matrix as C: The solution may be written in terms of the inverse of this matrix:

Compute the matrix of tristimulus values
In this final step, the tristimulus values of each primary are computed by multiplying the chromaticity coordinates by the tristimulus sum of the corresponding primary. While not necessarily an efficient implementation, this step may be written in matrix form, as noted in Eq (7), Note that the unfamiliar method had one fewer step than the familiar method.

Example 5.
The tristimulus values will be calculated for the BT.709 primaries, to produce a D 65 white point, as in the example for the familiar method. Note: ± is sign change (negation).
Note that the familiar method requires six fewer divisions than the familiar method, but three additional multiplications. The unfamiliar method thus has a slight, perhaps negligible, advantage in terms of computational burden over the familiar method (82 floating point operations, versus 85).

Limitations imposed by the unfamiliar method
The unfamiliar method will provide a solution when the determinant of the chromaticity matrix, C, is not zero. This determinant is the same as the determinant used earlier in Eq (3), that is, The inverse of C exists if and only if det(C) ̸ = 0. For any given white point, the tristimulus sums S R , S G , and S B may be computed if and only if C −1 exists. Further, once the tristimulus values of the white point have been specified, the matrix T may be computed using Eq (7) if and only if C −1 exists. Therefore, a necessary and sufficient condition for computing T, for a particular white point, is that det(C) ̸ = 0, or, equivalently, the area in the x, y chromaticity diagram enclosed by the primaries be non-zero. Therefore, the unfamiliar method imposes no additional constraints on the conversion from white point and chromaticity coordinates of primaries to tristimulus values of primaries. The primary chromaticity matrix, C, is the transpose of the numbers in the table immediately above, and its inverse is: Note that a solution for T was possible using the unfamiliar method, while the familiar method would fail because the quotients x B ÷ y B and z B ÷ y B do not exist.

Conclusions
In this paper, we have described two methods for computing the tristimulus values of a set of primaries needed to produce a specified white point in a stable-primary color space, given the white point of the color space and the chromaticity coordinates of the primaries. The first method, herein termed the "familiar method," is unable to provide a solution when any primary is aluminous, that is, its y chromaticity coordinate is zero. The second method, referred to in this paper as the "unfamiliar method," is able to provide a solution under the broadest set of conditions, i.e., whenever the primaries define a triangle of non-zero area in the x, y chromaticity diagram. While our nalysis shows that the familiar method involves a higher computational burden, its disadvantage relative to the unfamiliar method is slight (85 floating point operations, versus 82). We have shown both methods on practical parity with respect to computational burden, and that the familiar method imposes a constraint on the chromaticities. Because it offers solution when necessary and sufficient conditions for a solution are satisfied, including when one or even two primaries are one the alychne ("in the dark"), we recommend use of the unfamiliar method for future implementations.