Plotting Colors on Color Circle: Interconversion between XYZ Values and RGB Color System
Color is generated by optical properties of the pigments. Colors can be calculated by using color matching functions. Color-measuring apparatus such as colorimeters and digital cameras also provide convenient ways to analyze object colors. Color values are given in three dimensions, as a result of these measurements. Such preliminary color values are then converted to the other values such as hue, saturation, lightness, and coordinates in two-dimensional color plates. Interestingly, two different but mutually correlated color systems (color coordinates) are used in colorimetry: XYZ colors and RGB colors. XYZ colors have been mainly used to calculate colors, whereas we recently succeeded to plot colors on color circle based on the measurement of RGB colors. RGB color system also has the advantage of the ease of understanding: RGB color values represent intensities of red, green, and blue colors. The advantages of XYZ color system are that colorimeters measure XYZ values, and the accumulation of XYZ data in past publications. To combine the advantages of XYZ and RGB color systems, we summarized, re-calculated, and partly devised formulae for interconversion between XYZ, RGB, and coordinates on color circle in this study. Our formulae, when combined with the formulae in previous reports, enabled to convert between all these values.
We will recognize objects only by two factors in principle: shape and color; for example, 'green leaves' and 'red flowers'. As such, color of objects potentially has profound effects in both basic analytical studies and applications. Despite this significant importance of the analysis of colors (colorimetry), methods and theories in colorimetry are not fully understood, utilized, or developed by researchers. We will introduce the standard methods to measure and calculate colors first.
Figure 1 summarizes the ways how colors of objects are measured and calculated. Formally, colors are measured from surface reflectance spectra of opaque objects or transmittance spectra of transparent objects, R(λ). R(λ) spectra is measured by spectrophotometer such as UV-2450 (Shimadzu, Kyoto, Japan). Scientific definition of the range of 'visible light' is from 380 nm to 780 nm . Then, R(λ) is measured from 380 nm to 780 nm at 5-nm intervals. Spectra (spectral power distribution) of incident lights (L(λ)) also should be taken in account. Their spectra are measured by spectroradiometer such as MS-720 (EKO Instruments, Kyoto, Japan). Thus, the spectra of light reflected/transmitted at the object and coming into our eyes (Spec(λ)) is the multiplication between R(λ) and L(λ) :
Transmittance of transparent objects are often measured as the absorbance values (Asb(λ)). Transmittance is calculated from absorbance as follows :
Now we have the input data, Spec(λ), for color calculations.
Spec(λ) is converted to X, Y, and Z values in XYZ color space, or R, G, and B values in RGB color space by 'XYZ color matching functions' (x(λ), y(λ), and (z(λ)) or 'RGB color matching functions' (r(λ), g(λ), and (b(λ)), respectively. These color matching functions are not defined by formulae. Instead, values of the functions are given at 5-nm intervals, from 380 nm to 780 nm (Table 1) . We also devised a standardized version of the RGB color matching functions (FR(λ), FG(λ), and FB(λ); (Table 1) . Summation of the standardized RGB color matching functions along the whole range (380 nm - 780 nm) sums to unity (approximately 1). IR, IG, and IB values are obtained by the standardized RGB color matching functions. These calculations are summarized as follows:
In the history of colorimetry, RGB color space was originally generated, then XYZ color space was later derived from RGB color space. Thus, R, G, and B values are converted to X, Y, and Z values in a three-dimensional matrix :
XYZ color space is now more popular than RGB color space, but RGB color space is directly connected to our sense of colors: the three primary colors, i.e. red, green, and blue.
The most usual method of measuring object colors is not performed by color calculation with color matching functions, but by direct acquisition of X, Y, and Z values with colorimetric instruments. These instruments, such as CR-20 (Konica Minolta, Tokyo, Japan) measure X, Y and Z values in a moment, and automatically calculate XYZ-related coordinates such as L*a*b* coordinates. Here, 'L*a*b*' is also a color space, modified from XYZ color space so that the coordinates fit better with our sense of colors. The L*a*b* color space is usually adopted to plot the measured object colors. It seems that the L*a*b* color space is often considered to be a perfect color space, plotting all colors on a color circle at the even hue angles. Here, 'hue' represents the type of colors like red, green, and blue. There are also two other factors in colors: lightness (brightness) and saturation (vividness). Saturation is expressed as the distance from the origin, in color circle. Lightness is not expressed in color circle. With the lightness expressed as the third factor, color circle forms a color cylinder. Then, a*-b* color plate of the L*a*b* color space is not actually a circle. Its shape is largely distorted from the circle, and the hues are not evenly placed around the origin. Accordingly, it is quite difficult to describe, on the a*-b* color plate, which hue angles correspond to specific colors such as red, orange, yellow, green, cyan, blue, and magenta. This inconsistency between the popular color measurements and the expected output data was found in our previous report .
Certainly, it is quite convenient to use colorimetric instruments to quickly and automatically obtain color coordinates, but there will be problems in these XYZ-based methodologies, when it comes to scientific description of object colors, and the compatibility of the obtained data with our sense of colors. For instance, response curves of colorimetric instruments manufactured by private companies are company secrets and never open to the public. It is easily imaginable that the response curves of these instruments are much different from the color matching functions, or otherwise resolution of light wave length may be greatly rough. Another problem is that the usually used L*a*b* color space (or a*-b* color plate) is much distorted from the color circle, as described above.
An effective solution to these problems are direct calculation of object colors from reflectance/transmittance values, and going way back to the original RGB color system, from the modified XYZ color system [1-3]. In the RGB-based color coordinates, standardized values (IR, IG, and IB) are directly calculated as in the formulae (3), or they are calculated from R, G, and B values:
Thus, summations of IR, IG, or IB along the whole range of visible wave lengths are almost unity (1.00003, 1.00000, or 0.99999; Table 1). It is not a strict measurement of colors, but RGB values which correspond to IR, IG, and IB can be also easily recovered from digital photographs, by using the software like Adobe Photoshop. The RGB lightness (LRGB) is calculated as follows:
Relative proportions of IR, IG, and IB and are also calculated:
The RGB hue (HRGB) is calculated from these values:
The HRGB values are given as angles in degrees. These angles are evenly distributed around the origin, and the abbreviations in single capital letters are given every 30°: red (R, 0°/360°); orange (O, 30°); yellow (Y, 60°); lawn (L, 90°); green (G, 120°); emerald (E, 150°); cyan (C, 180°); azure (A, 210°); blue (B, 240°); violet (V, 270°); magenta (M, 300°); pink (P, 330°). The origin is white (W), without any hue angle (Figure 2).
Calculation of the saturation values is not simple, because this is the biggest reason that causes distorted shapes of color plates. A preliminary value of the RGB saturation (SRGB) is calculated from and values:
The maximum values of SRGB are almost unity between the hue angels of 0° and 120°, and between 240° and 360°, but they greatly exceed unity between 120° and 240°. This phenomenon is caused by the negative R values in highly saturated cyanic colors. The SRGB values between 120° and 240° are approximated with the following formula (ASSCC; approximated saturation of saturated cyanic colors) :
Then, the RGB saturation is rounded to realize the unity of the maximum values (SRGB2) with ASSCC (HRGB):
The RGB values recovered from digital photographs do not have negative values, then this calculation with ASSCC will not be necessary for such data.
To summarize, SRGB2, HRGB, and LRGB values represent evenly distributed colors on the color circle (or in the color cylinder), which perfectly fit with our sense of colors. Color coordinates on the color circle (r-d coordinates on the round color diagram) are as follows (Figure 2):
As shown in the Figure 1, several steps of mathematical conversions are necessary to calculate each colorimetric value. These mathematical conversions have been one-directional: the upstream values such as RGB and XYZ are calculated to obtain downstream values such as L*a*b*and r-d coordinates. The formulae for calculations in reverse directions are not described in previous literatures. In the present study, we will derive the formulae to calculate in reverse directions. These formulae enable interconversion between RGB values, XYZ values, and r-d coordinates (i.e. plots on the color circle).
Materials and Methods
Calculation of the inverse 3 × 3 matrix
Inverse 3 × 3 matrices can be calculated by a formula. Instead of using the formula, we input data into a website  which automatically calculated the inverse 3 × 3 matrix.
Measurement of the leaf color
Leaves were excised from cherry blossom tree (Prunus sp. cultivar 'Taoyame') in spring. The XYZ values of five leaves were measured with CD100 colorimeter (Yokogawa Meters & Instruments Corp, Tokyo, Japan), and the median value (third largest value of the five measurements) was used for calculations.
Interconversion between XYZ and RGB values
The X, Y, and Z values are calculated from R, G, and B values as in the formulae (4). Formulae (4) form a 3 × 3 matrix, then the inverse matrix of the formulae (4) immediately derives the following formulae:
By using these formulae, now it is possible to convert XYZ values, which were measured in colorimetric instruments, to RGB values. Interconversion between XYZ values and L*a*b* coordinates is not the target of this study, but this interconversion will be also possible.
Reverse calculation of HRGB and SRGB2 from r-d coordinates
The r-d coordinates are the positions on the color circle, and calculated from HRGB and SRGB2 by the formulae (12). The back calculations of HRGB and SRGB2 from the r-d coordinates are simple, just following the standard trigonometric functions. HRGB is the angle of the line connecting between r-d coordinates and the origin. SRGB2 is the distance of the r-d coordinates from the origin:
The lightness value is not reflected in the plots on the color circle, so the value of LRGB cannot be calculated from the r-d coordinates. The lightness values should be prepared separately, or alternatively, the colors are simply calculated without lightness values.
SRGB is back calculated from SRGB2 as follows:
Reverse calculation of RGB values from HRGB, SRGB, and LRGB
The HRGB and SRGB values obtained above are first converted to and values. This calculation is performed in simultaneous equations, consisting of three first-degree equations. First, the values of and always sum to unity:
Second, the HRGB is an arctangent value calculated in the formula (8). Then, its back calculation is as follows:
This formula is transformed as:
Third, SRGB was calculated from the minimum value among and in the formula (9). The minimum value among these three values is determined by the hue angles. Thus, the back calculation of the formula (9) is:
Calculating the simultaneous equations (16), (17), and (18) gives and values. Then, IR, IG, and IB values are:
Finally, R, G, and B values are:
Example of color calculation
An example of the calculation of the RGB-based colorimetric values from an XYZ data set will be demonstrated here, for better understanding of the calculations.
An XYZ data set was measured with a colorimeter, on a leaf of cherry blossom tree (Figure 3). These values were (X, Y, Z) = (5.420, 7.965, 2.077). This data set was converted to RGB data set by using the formulae (13), obtaining the values (R, G, B) = (0.8322, 1.5492, 0.3556). By using the formulae (5), these values were standardized, so that (IR, IG, IB) = (0.2200, 0.4096, 0.0940). Sum of these values represents the RGB lightness, according to the formula (6), then (LRGB) = (0.7237). Following the formulae (7), ratios of IR, IG, and IB are: IR, IG, and IB = (0.3041, 0.5660, 0.1299).
The HRGB and SRGB values are calculated with formulae (8) and formulae (9): (HRGB, SRGB) = (96.6°, 0.6102). At this angle of HRGB, SRGB2 is the same as SRGB formulae (11): (SRGB2) = (0.6102). At last, the r-d coordinate is calculated by the formulae (12): (r, d) = (-0.070,0.606).
RGB-based color of the cherry leaf
As an example of color calculation, we measure and calculated the color of a cherry leaf. Here, how are the RGB-based colorimetric values estimated, in the terms of colorimetry? Let us check the meaning of each colorimetric value one by one.
To begin with, the values of IR, IG, and IB were approximately 0.22, 0.41, and 0.09, respectively. Because these values have been standardized so that the maximum value is 1, these values mean that the color of this leaf is interpreted as the mixture of 22% strength red light, 41% strength green light, and 9% strength blue light. At this point, we can deduce that this color is greenish, but a bit yellowish. LRGB value was 0.72. Considering that the maximum value of LRGB is 3, the leaf is not so much blight. These speculations would be consistent with the true color of this leaf (Figure 3).
The color profile is completely clear with the HRGB and the SRGB2 values. The HRGB value was 97°. This hue angle is a bit more greenish that the lawn color (L; yellow-green; 90°). SRGB2 value was 0.61, representing that the color is 61% vivid compared with the full saturation value. With the r-d coordinate of (-0.07, 0.61), the color of this leaf is plotted at this position on the unit color circle (Figure 2).
Interconversion between colorimetric values
In this study, we calculated the formulae to convert XYZ values to RGB values. This important calculation is not mentioned for the first time in this study. The formulae to convert XYZ values to RGB values have been reported in past publications [6,7], but these formulae are different from each other. This is probably because different versions of XYZ and/or RGB color matching functions were used to derive these formulae. We then re-calculated the formulae, based on seemingly the most standard XYZ and RGB color matching functions, by showing their values in Table 1. The resulting formulae (13) were quite similar to the ones on a website . Thus, it was confirmed that the formulae (13) and the formulae on the website are suitable for conversion of the standard XYZ values to the standard RGB values.
Because object colors are usually measured as XYZ colors, such colorimetric data has been almost always plotted onto the XYZ-related color plates, such as the a*-b* color plate [8,9]. Our formulae for conversion of the XYZ values to the RGB values connected these color systems each other, and enabled to calculate the coordinates on the color circle, even from the XYZ values. Unlike the largely distorted XYZ-based color plates, the RGB-based color circle and the colorimetric values can be readily interpreted to color names, such as orange and purple . From now on, researchers calculating object colors by either XYZ values or RGB values are recommended to calculate RGB-based colorimetric values, and plot colors on the color circle.
We also derived a series of formulae to back calculate RGB values from the coordinates on the color circle. These calculations are relatively complicated, but possible. By using these formulae, for example, the proportions of three primary colors (red, green, and blue) can be identified for any part of the color circle. This will help generating specific colors by mixture of lamps with different visible light spectra. As we reported in previous papers, colorimetric effects such as 'dichromatism' and 'alexandrite effect' can be also analyzed by following rigid spectral calculations [2,3]. These are just examples of possible applications, and the relationship between the whole colorimetric values, clarified in this study, potentially contributes to any aspect of colorimetric analyses.
- (2004) Colorimetry. (3rd edn), Commission Internationale de l'Eclairage, CIE Publ 15, Vienna.
- Kasajima I (2016) Alexandrite-like effect in purple flowers analyzed with newly devised round RGB diagram. Sci Rep 6: 29630.
- Kasajima I, Sasaki K (2014) Dichromatism causes color variations in leaves and spices. Color Res Appl 40: 605-611.
- Kasajima I, Fekih R (in press) Eating colors: a scientifically based perception of food colors. Jacobs J Food Nutr.
- Hunt RWG, Pointer MR (2011) RGB Colorimetry. Measuring colour. Wiley, Hoboken, USA.
- Katsumoto Y, Fukuchi-Mizutani M, Fukui Y, et al. (2007) Engineering of the rose flavonoid biosynthetic pathway successfully generated blue-hued flowers accumulating delphinidin. Plant Cell Physiol 48: 1589-1600.
- Noda N, Aida R, Kishimoto S, et al. (2013) Genetic engineering of novel bluer-colored chrysanthemums produced by accumulation of delphinidin-based anthocyanins. Plant Cell Physiol 54: 1684-1695.
- Kasajima I, Ohtsubo N, Sasaki K (2017) Combination of Cyclamen persicum Mill. floral gene promoters and chimeric repressors for the modification of ornamental traits in Toreniafournieri Lind. Hort Res 4: 17008.
Ichiro Kasajima, Faculty of Agriculture, Iwate University, Ueda 3-18-8, Morioka, Iwate 020-8550, Japan, Tel: +81-19-621-6103.
© 2017 Kasajima I. This is an open-access article distributed under the terms of the Creative Commons Attribution License, which permits unrestricted use, distribution and reproduction in any medium, provided the original author and source are credited.