<<

hydrolight technical note 5

Conversion of spectra to

Curtis Mobley January 2007

These notes discuss the conversion of radiance or irradiance spectra into various measures of “color” as perceived by the human eye. See and Water Chapter 2 for the background information needed to understand CIE coordinates, which is where this discussion begins. For further details and some very nice applets and spreadsheets, see the excellent color science web site maintained by Bruce Lindbloom at www.brucelindbloom.com. A web search will reveal many more useful sites.

First, keep in mind that the color you see—or the reflected radiance spectrum that an instrument records—depends both on the material being observed and on the spectrum of the light that is illuminating the scene. Simply put, if I shine a “” light onto a “white” wall, the wall looks white. But if I shine a light onto a white wall, the wall looks red. Thus we start by noting that various standard illuminants or reference are used for various purposes (human vision studies, computer displays, graphic arts, etc.). For example, E has the same power at every wavelength and is implicitly assumed to be the illuminant when converting a spectrum to CIE (x, y) chromaticity coordinates. Thus illuminant E has (x, y) = (0.333, 0.333), which is the of the CIE chromaticity diagram (Fig. 3 below). Standard is similar to daylight on a clear day and has much the same general shape for wavelengths greater than 450 nm as a -body spectrum for a temperature of 6,500 K. Although the extraterrestrial solar spectrum corresponds more closely to a temperature of about 5,800 K, the addition of scattered sky light makes the overall daylight spectrum a bit bluer than direct . Thus the correlated —the temperature of a radiator that most closely matches a given spectrum—is higher than the sun’s surface temperature. D50, which is widely used in graphic arts, is a bit redder than sunlight and corresponds roughly to a black body curve for 5,000 K. Illuminant A mimics incandescent light sources—a very red spectrum corresponding to a temperature of 2,856 K, which is about the temperature of the tungsten filament in a 100 W light bulb at 120 V. Illuminant F2 corresponds to a “cool white” fluorescent light, and so on. Figure 1 shows the shapes of the D65, E, and blackbody(6500 K) functions. The figure also shows a spectrum that is metameric to D65, which means that it has exactly the same (x, y) = (0.313, 0.329) coordinates as D65. This particular spectrum is non-zero at only 450, 550, and 650 nm. The human eye-brain system perceives the the continuous D65 spectrum and this three-wavelength spectrum as having exactly the same color. Each spectrum in Fig. 1 is normalized to 1 at its maximum value.

1 Fig. 1. Standard illuminant E, red; D65, ; a 3-wavelength spectrum that is metameric to D65, ; and a blackbody spectrum for 6,500K, black. Each spectrum is normalized to 1 at its maximum value.

The reason a “daylight” color film photograph made under incandescent looks sickly is that a typical daylight film assumes that the illumination is close to D65. To get good color reproduction under incandescent , you need to switch to a film designed for illuminant A, or add an appropriate filter to the lens to “transform” the daylight into incandescent light before the light reaches the film. Digital cameras let you select the assumed illuminant before taking a picture (generally called “white balance”). In most digital cameras you pick “daylight,” “cloudy,” “fluorescent,” etc. from a menu, but you’re really selecting the standard illuminant to be used in generating the RGB values in the image. Alternatively, you can “re- balance” a digital photo afterwards using software such as PhotoShop.

The message for the moment is simply that when quantifying the “color”of something, it is also necessary to specify the illuminant used. Also keep in mind that the color as perceived by the human eye-brain system is affected by the field of view, the of adjacent areas, the overall brightness, and even the spatial pattern and motion of the object being viewed. There are many “optical illusions” involving perceived colors. See the web site www.michaelbach.de/ot/ for some excellent examples.

2 Computation of CIE XYZ and xyY Color Coordinates

Let F(ë) represent any spectrum. This could be the downwelling irradiance, the water- leaving radiance, or the radiance emitted by a computer screen. Then the color components of F are given by (L&W Eq. 2.10)

(1)

(2)

(3)

-1 Here are the tristimulus functions shown in Fig. 2, and Km = 683 lm W .

(Note that L&W has a typo on page 49, where it gives Km = 638.) The [X, Y, Z] triple of numbers defines both the color and the brightness of the spectrum. The tristimulus function is the photopic luminosity function. Thus Y is the luminance in lm m-2 sr-1 if F is a radiance in W m-2 sr-1 nm-1, and Y is the illuminance in lm m-2 if F is an irradiance in W m-2 nm-1.

Fig. 2. The CIE 1931 tristimulus functions for use in Eq. (1). is red, is green, and is blue.

3 The color of a spectrum as seen by an “average” human eye, without consideration of the brightness, is usually expressed by the chromaticity coordinates (x, y), where

x = X/(X+Y+Z) and y = Y/(X+Y+Z). (4)

The brightness is expressed by the luminance Y, computed by Eq. (2). Thus the (x, y, Y) triplet of numbers specifies both the color and brightness, as does the [X, Y, Z] triplet.

The color (x, y) is usually plotted on a chromaticity diagram, as seen in Fig. 3. The colors in Fig. 3 were captured from a and do not correspond exactly to the actual colors seen in nature, and will be even more unrealistic if printed out, for reasons discussed in the next section.

Figure 4 shows two spectra for water-leaving radiances Lw as generated by HydroLight for Case 1 water with very low (Chl = 0.02 mg m-3) and very high (Chl = 50 mg m-3) chlorophyll values, along with the E and D65 standard illuminants. The corresponding (x, y) points for these four spectra are indicated by the symbols in Fig.3.

Fig. 3. The CIE 1931 chromaticity diagram; the colors are only approximate. The symbols correspond to the spectra seen in Fig. 4. The white point, corresponding to standard illuminant

E is the circle at (x, y) = (0.333, 0.333). The square is D65; the diamond is Lw(Chl=0.02), and

the triangle is Lw(Chl=50).

4

Fig. 4. Spectra illustrated in Fig. 3. Standard illuminant E is red; D65 is purple; Lw(Chl=0.02) is blue, and Lw(Chl=50) is green. Each spectrum is normalized to 1 at its maximum value.

In summary, there are two great virtues of the CIE (x, y, Y) coordinates: (1) any spectrum has corresponding (x, y, Y) values and, (2) the (x, y, Y) values are device independent, i.e., they don’t depend on a particular display device such as a computer monitor or color printer.

Computation of RGB values

Computer monitors and TVs have three different light sources grouped together in small pixels. One source generates red light, one green, and one blue—as perceived by the human eye. Each source can generate various levels of brightness for each color. Computer monitors thus use a triplet of Red, Green, and Blue (RGB) values to define how much of each is used to generate a desired color. In most monitors, each value of R, G, or B ranges from 0 (no light of that color emitted; the pixel is turned off) to 28-1 = 255 (maximum brightness). This is usually called “8 bit/” or “24 bit,” i.e. 3x8, color. These 256 brightness levels for each primary color give a total of 2563 = 16,777,216 different colors and levels of brightness that can be displayed, even though the human eye can perceive differences in far fewer colors and brightness levels. Digital cameras likewise store images in terms of RGB values.

Converting a spectrum F(ë) into [X, Y, Z] and then into [x, y, Y] values is easy, as seen above in Eqs. (1)-(4). Converting between [X, Y, Z] and [R, G, B] values is complicated.

5 The , or range, of colors detectable by the human eye is the colored (x, y) region of the CIE chromaticity diagram seen in Fig. 3. This gamut is generated, in a manner of speaking, by various mixtures of all of the pure colors found on the curved spectrum locus. There is no way that only three colors can be combined to generate all of the colors seen by the eye. For example, if my computer monitor had small lasers emitting light at 473, 532, and 670 nm (diode lasers are available at these wavelengths), rather than three LCDs (liquid crystal diodes), then these pure colors could be combined to represent any color within the large dashed-line triangle seen in Fig. 5. This hypothetical “diode laser RGB” gamut covers much, but not all, of the gamut of colors detectable by the eye.

The PC computer industry (MicroSoft and Hewlett Packard in particular, see Stokes et al., 1996) has defined an RGB or , i.e. a gamut of colors, for use with PC monitors. This color model, called sRGB, assumes the D65 standard illuminant and is the gamut of colors that can be generated on most PC computer monitors. (Not surprisingly, Apple has its own color model, as does Adobe, and there are many others.) The conversion from sRGB to XYZ coordinates is given by (See www.brucelindbloom.com for the details. Also, for convenience I’m writing [X, Y, Z] and [R, G, B] as row vectors in the text, but in the equations it’s conventional to use column vectors.)

(5)

The RGB values in Eq. (5) are considered to be between 0 and 1; they must be rescaled to 0-255 for 24-bit color computer display (more on this on page 9). Using Eq. (5) to convert [R, G, B] = [1, 0, 0] gives [X, Y, Z] = [0.412424, 0.212656, 0.0193324], which gives (x, y) = (0.640, 0.330). Converting [0, 1, 0] gives (x, y) = (0.30, 0.60), and [0, 0, 1] gives (x, y) = (0.15, 0.06). These three (x, y) values define the vertices of the sRBG gamut triangle seen in Fig. 5.

Conversion from [X, Y, Z] to [R, G, B] for the sRBG color model is done by the inverse of the 3x3 matrix in Eq. (5):

(6)

6

Fig. 5. The CIE chromaticity diagram with the “diode laser RGB” gamut shown by the large dash-line triangle. The solid-line triangle is the sRGB gamut. The small symbols are the same as in Fig. 3.

The sRGB gamut seen in Fig. 5 covers only part of the CIE color diagram. Thus it isn’t possible to reproduce the true colors of the CIE diagram on a computer screen, or on any other device with a gamut that is less than that of the human eye. The best I could do in creating Fig. 5 was to generate colors for the spectrum locus using various RGB values and then interpolate from those colors at the outside of the figure to the [R, G, B] = [255, 255, 255] white point at the center. This was done by trial and error until the result looked good enough for these notes. Although the resulting display shows the general pattern of colors in the CIE diagram, the true colors are certainly something different than what is seen in Fig. 5, especially in the green region.

Now consider standard illuminant E with a magnitude of 1.0 at each wavelength, as shown in Fig. 1. Using this E for F(ë) in Eqs. (1)-(3) gives [X, Y, Z] = [7.3C10444, 7.3C10 , 7.3C10 ]. Equation (6) then gives [R, G, B] = 7.3C104[1.205, 0.948, 0.909]. For computer display, we can re-scale these RGB values to the 0-255 range. If we rescale so that the largest value is 255, we get [255, 201, 192]. In any case, there is more red than green or blue in this RGB triplet; thus the displayed color is , not white as might be intuitively expected for the “pure white” standard illuminant E. The reason for this color mismatch is that sRBG assumes the D65 standard illuminant, whereas the CIE 1931 chromaticity diagram assumes standard illuminant E.

7 If we let F(ë) = D65 as seen in Fig. 1, then [X, Y, Z] = [5.82C10444, 6.13C10 , 6.66C10 ] and Eq. (6) gives [R, G, B] = 6.12C104 [1, 1, 1]. This RGB has equal amounts of red, green, and blue and displays as white, if scaled to [255, 255, 255]. Thus the D65 spectrum generates “pure white” in the sRBG color model, which assumes that the reference white is D65, and the computations are consistent.

If we want to convert XYZ values to RGB and get equal amounts of RGB for spectrum E, we have to use a conversion matrix that assumes standard illuminant E for the reference white. This matrix is (www.brucelindbloom.com)

(7)

Using the illuminant E values [X, Y, Z] = 7.3C104 [1, 1, 1] from above in Eq. (7) gives [R, G, B] = 7.3C104 [1, 1, 1]; i.e., there are equal amount of red, green, and blue, and the monitor display is white (or some shade of gray, depending on how you rescale the values between 0 and 255). This illustrates the importance of being consistent with which standard illuminant is assumed for color rendition. The inverse matrix corresponding to standard illuminant E is

(8)

Using [R, G, B] = [1, 1, 1] in Eq. (8) gives [X, Y, Z] = [1, 1, 1], as expected. The D65 spectrum of Fig. 4 has (x, y) = (0.313, 0.329), which is the location of the square symbol in Figs. 3 and 5. Converting D65 to RGB using Eq. (7) gives [R, G, B] = [196, 242, 255], which is a pale blue. In other words, D65 is a bit bluer than the assumed reference white E for Eqs. (7) and (8).

Thus to summarize, when converting spectrum E to RGB using the sRGB color model we got a pale red color, [R, G, B] = [255, 201, 192], because sRGB uses D65 as the reference white. When converting D65 to RGB using the CIE color model, we got a pale blue color (the square in Figs. 3 and 5), [R, G, B] = [196, 242, 255], because the CIE color model uses E as the reference white. These two colors as displayed on my monitor are shown in Fig. 6. These colors as seen on your particular monitor when reading this, or as printed on a color printer, likely will be noticeably different that what I’m seeing on my monitor as I write this. These results show the importance of accounting for the underlying standard illuminant and color model when generating colors for display and comparison with what the eye sees.

8

Fig. 6. The pale blue color on the left is the D65 spectrum converted to [R, G, B] = [196, 242, 255] using Eqs. (1)-(3) and (7). The pale red color on the right is the E spectrum converted to [R, G, B] = [255, 201, 192] using Eqs. (1)-(3) and (6).

There are additional complications inherent in the XYZ to RGB transformation. First, after applying the transformation of Eq. (6) to an XYZ triple, where X, Y, and Z are between 0 and 1, it is common to apply a “” to redistribute the resulting RGB values to get better color reproduction. Thus the RGB values from Eq. (6) are further transformed by (www.brucelindbloom.com)

if R #0.0038808 then reset R to 12.92R if R >0.0038808 then reset R to 1.055R1/2.4 - 0.055 for the sRGB color model. The same transformation is applied to G and B. Note that the transformations of Eqs. (5) and (8) should be applied to untransformed (“linear”) RGB values, not to gamma-transformed values.

Second, you often have to make a subjective decision on how to rescale the RBG values to get the right brightness when displayed. Keep in mind that gray is just white that “isn’t very bright.” For example, Dierssen et al. (2006) found that normalizing [X, Y, Z] so that Y = 0.4 gave RGB values in the mid-range of brightness and reasonable screen colors from RGB values computed by Eq. (6) and multiplied by 255 (the max of R, G, and B is then generally less than 255). The value of Y = 0.4 was an ad hoc choice determined by trial and error for visual appearance of ocean radiance spectra colors. In Fig. 6 I scaled the computed RGB values so that the largest value was 255, which gives the brightest image on screen. This may not give realistic colors for measured ocean reflectances, which often appear very dark blue or green. Figure 7 shows an example of a “pure red” display, i.e, [R, G, B] = [R, 0, 0], for R = 255, 200, 150, and 100. The visual appearance changes from “bright red” for R = 255 to “dark ” for R = 100 (in other words, brown is just red that isn’t very bright). Thus the perceived color depends on the brightness of the image, as well as on spectral shape.

9 Fig. 7. Screen colors for [R, G, B] = [R, 0, 0], for R = 255 (leftmost), 200, 150, and 100 (rightmost).

Third, note that the RGB to XYZ 3x3 transformation matrices in Eqs. (5) and (8) have positive elements. Thus any [R, G, B] triplet of positive numbers generates an [X, Y, Z] triplet of positive numbers, i.e. a valid point (x, y) in the CIE diagram. That is to say, any RGB color can be represented on the CIE diagram. However, some of the matrix elements in Eqs. (6) and (7) are negative. This means the not every valid XYZ or (x, y) can be represented by valid RGB values for a given color model.

Consider the green spectrum seen in Fig. 4, which was generated by HydroLight for Chl = 50 mg m-3. This normalized spectrum has [X, Y, Z] = [163, 190, 117], or (x, y) = (0.347, 0.404). This is a yellowish green color on the CIE diagram, as shown by the small triangle symbol in Fig. 3. Converting this XYZ to RGB by Eq. (6) for the sRBG color model and scaling to 255 for the maximum value gives [R, G, B] = [223, 255, 117] which, when displayed, is also a yellowish green. The blue spectrum of Fig. 4, which was generated for Chl = 0.02, has [X, Y, Z] = [188, 125, 845], or (x, y) = (0.162, 0.108). This point is shown by the diamond symbol in Figs. 3 and 5. Using this XYZ in Eq. (6) gives a negative red value: [R, G, B] = [-2, 26, 255]. This is not a valid color for display on the computer monitor. Note that this (x, y) point lies just outside the sRGB triangle seen in Fig. 5. This situation is not uncommon because the sRBG color gamut is far smaller than the gamut of colors in the CIE diagram. Indeed, the sRGB color space represents only 35% of the CIE (x, y) color space. In other words, only 35% of the colors as seen by the eye can be accurately reproduced on a computer monitor. About all you can do in this situation is set the -2 to 0 and hope that the displayed color is not too different from what your eye would see in nature. It is also easy to get RGB values greater that 1 (or greater than 255 after scaling); likewise, all you can do is set a value greater than 255 to 255 and hope for the best, keeping in mind that the equations are telling you that the color of your spectrum as seen by your eye cannot be reproduced on the computer monitor. This may not be a serious problem unless you take your computer into the field and compare its displayed screen color side by side with the color of the water or other object as seen by eye while measuring the F(ë) spectrum that gives the RGB values.

10 Fourth, color reproduction gets even more complicated when printing. Computer monitors are emitting light, and various colors are generated by adding together different amounts of red, green, and blue light. Thus yellow is generated by turning on the red and green pixels. Likewise, the RGB system is an system. When viewing colors on a printed page, you are seeing reflected light. The dyes in the ink absorb, or subtract, various colors from the incident (usually white) light. The printing industry thus deals with subtractive colors, e.g., yellow is generated by subtracting blue from white. Color printers thus use the CMYK (, , yellow, black) system, which specifies how much ink of various colors to put onto the page, rather than how much light to generate. Some printers have additional ink colors. Thus the color space or gamut for a printer, when plotted on a CIE diagram, will have more than three vertices if the printer uses more than three colors of ink. This can give better coverage of the human vision color space than can a 3 color RGB system. Needless to say, converting a computer screen image from RGB to CMYK values is a messy business, and full account of the standard illuminants and color models for the monitor and the printer must be taken into account. This is what is done in PhotoShop, for example, when you do a “save as CMYK” on an RGB file. The resulting printed image may or may not be satisfactory, depending on whether or not the underlying color models are consistent with the printer to be used.

Finally, if you want to get really serious about reproducing color, you need to install the correct “ICC Profile” to explicitly manage color on your particular monitor or printer (International Color Consortium, see http://www.color.org/ for discussion of ICC profiles). After downloading the ICC profile for your device (a file with a “.icc” extension—and good luck on finding the right one for a device that is now last year’s model), you then have to install it. On a Windows computer, this is done someplace well hidden, such as (on my Windows XP computer) Control Panel –> Printers and Other Hardware –> Monitors –> Settings –> Advanced –> –> Add.

OK, enough said about color. It ain’t simple. HydroLight computes the (x, y, Y) values for

Lw, Lud, E , and Eu spectra whenever the run covers at least the 400-700 nm range. (The calculations are done in subroutine CIExyY.f; the output is at the bottom of the printout file.) These quantities can be uniquely determined for any spectrum. However, HydroLight does not attempt to compute corresponding RGB values because these values are device dependent and require additional, sometimes subjective, scaling to get good color reproduction. If you want to turn your spectra into RGB or CMYK values, you can start with the [X, Y, Z] values computed in subroutine CIExyY, but beyond that you’re on your own. Just beware: these notes barely get you started into the very complicated business of color management.

11 Acknowledgements

I am indebted to Heidi Dierssen, whose excellent talk at Ocean Optics XVIII got me interested in the problem of computing RGB values from HydroLight spectra. Eric Rehm made many useful comments on my draft manuscript.

References

Dierssen, H., R. M. Kudela, J. P. Ryan, and R. C. Zimmerman, 2006. Parting the red seas: The bio-optics of red tides. Invited presentation at Ocean Optics XVIII, Montreal, Canada. The full paper is “Red and black tides: Quantitative analysis of perceived color for phytoplankton, colored dissolved organic matter, and suspended sediments,” Limnol. Oceanogr., in press.

Light and Water. Available on CD from Curtis Mobley or at www.curtismobley.com/lightandwater.zip.

Stokes, M., et al., 1996. A standard default color space for the internet - sRGB. Available at www.w3.org/Graphics/Color/sRGB

12