René Krieg How to Bring Natural Light on a Monitor Technical Note No. 004 (Version 1.1) Copyright c January 22, 2015, LightTrans GmbH, Jena All rights reserved.
Content 1. The Problem...3 2. CIE Chromaticity Coordinates - A Model for Color Perception...4 3. Converting Chromaticities to RGB...6 3.1. Which RGB system?...7 3.2. Transformation Algorithm...8 3.3. Gamma correction...9 4. Color Profiles and Monitor Calibration...11 2
1TheProblem To display colorful light of one or several defined wavelength(s) on a computer monitor as naturally as possible is not trivial. At least two factors have to be considered: The wavelength dependent sensitivity of the human eye which is responsible for the man s ability to recognize colors, and the properties of the monitor and its color generating technology. So the wavelength-to-monitor-color algorithm consists of several steps, outlined in Fig. 1. At first the single wavelength of monochromatic or the wavelength combination of polychromatic light have to be converted into some kind of physiological representation of light, which means to determine their coordinates in the perceptional color space. Then, in order to simulate this human perception as naturally as possible by the R, G and B phosphors of the monitor, a transform into an RGB color space has to be done, whose results will be displayed by the graphics card using the color profile of the calibrated monitor. The algorithm described here was inspired by that found on http://www.fourmilab.ch/documents/specrend. Figure 1. The Algorithm that is Used to Bring Natural Light on a Monitor 3
2 CIE Chromaticity Coordinates - A Model for Color Perception The so called Color Matching Functions 1, which relate the full visible spectrum (360 nm to 830 nm) to the three primary colors red, green and blue, have been measured in 1931 and in 1964 via physiological experiments by the Commission Internationale de l Éclairage (CIE) 2. These three functions give for every single wavelength the stimulus intensity for the three kinds of color sensual cells (retina cones) and are shown in Fig. 2. Figure 2. The Color Matching Functions. So we get an objective (that means device independent, because physiological) representation of monochromatic light of the wavelength λ which can be written as a triple of the three values of the Color Matching Functions (X(λ), Y(λ), Z(λ)). For the analogous representation of polychromatic light in the wavelength range λ min to λ max an additional step is required. The values X, Y and Z have to be summed separately for all wavelengths, weighted by the power spectrum P (without measuring units) of the light source: X Σ = Y Σ = Z Σ = λ max λ=λ min X(λ)P(λ) λ max λ=λ min Y(λ)P(λ) λ max λ=λ min Z(λ)P(λ) 1 That can be found on http://www.cvrl.org/cie.htm and which were published in [CIE32]and[CIE64]. 2 Which of these two measurements has to be used depends, technically speaking, on the choice of the RGB system the values will be converted to (see Section 3), because the definition of each non perceptional color system is referenced to either the 1931 or the 1964 data. For the sake of simplicity, only the 1931 data are used within VirtualLab TM. 4
As a preparation for the conversion to device RGB colors, the (X Σ, Y Σ, Z Σ ) values are converted to the so called chromaticities (x, y, z) by: x = X Σ /(X Σ + Y Σ + Z Σ ) y = Y Σ /(X Σ + Y Σ + Z Σ ) z = 1 x y These values provide a two-dimensional representation of the color space, neglecting luminosities. It is visualized by the chromaticity diagram (Fig. 3), that shows the chromaticity coordinates of all colors at a glance. The pure spectral colors are located at the upper boundary curve (labeled with the wavelengths). 0.9 y 0.8 0.7 0.6 0.5 0.4 0.3 525 515520 530 535 510 540 545 550 505 555 560 565 570 500 575 580 585 590 495 595 600 605 610 620 490 635 700 0.2 485 0.1 480 475 470 460 380 0.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 x 0.8 Figure 3. TheCIEChromaticityDiagram.Thepurecolors(spectralcolors)lieon the upper boundary curve and are marked by their wavelengths in Nanometers. The lower boundary line marks the so called purple line and contains mixed colors not contained in the rainbow. Source: The original graphic for this, as well as for all following chromaticity diagrams, was made by Gernot Ho=mann (http://www.fho-emden.de/ hoffmann), subsequently modified by LightTrans. 5
3 Converting Chromaticities to RGB The conversion from the perceptional color space to RGB colors is done via the transformation matrix T by r x g = T y. (3.1) b z It is important to know that there is not only one unique RGB color space. Although there exist some standards like srgb or AdobeRGB, every RGB system has to be defined in relation to the perceptional color space. This is done by four pairs of values, i.e. the chromaticity coordinates of the three primary colors (r x, r y ), (g x, g y ) and (b x, b y ), and the white point (w x, w y ). In Fig. 4, you can see the location of two di=erent RGB color spaces (srgb and LightTrans Color System) in the chromaticity diagram. 0.9 y 0.8 0.7 0.6 0.5 0.4 0.3 525 515520 530 535 510 540 545 550 505 500 LightTrans Color System 495 490 srgb WP WP: White Point of srgb and LightTrans Color System 555 560 565 570 575 580 585 590 595 600 605 610 620 635 700 0.2 485 0.1 480 475 470 460 380 0.0 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 x 0.8 Figure 4. The position of the srgb and the LightTrans Color System in the chromaticity diagram. The vertices mark the primary colors while the dot in the middle show the white point. The area inside the triangles is called gamut and contains all displayable colors. Source: see Fig. 3 6
The region of all colors that are displayable in a certain color space is called gamut and is equivalent to the area inside the triangle in the diagram 1.If a color lies outside the gamut of an RGB color system to use, it can only be approximated by one of the colors inside. The algorithm to find an appropriate substituting color is called out-of-gamut handling 2.Itisofparticular interest for the task of displaying natural light, because of the fact that all pure / spectral colors are located outside the most of the RGB color space gamuts. The matrix T in Eq. 3.1 has to be calculated from the chromaticity coordinates of the three primary colors (triangle vertices) (r x, r y ), (g x, g y ) and (b x, b y ), and the white point (w x, w y ). This will be shown in the Section Transformation Algorithm. But what color system has to be used for that? 3.1 Which RGB system? The best way would be to convert the CIE values directly to the monitor s individual RGB color system. But due to practical reasons (like the display algorithm s performance) for VirtualLab TM I chose the following way that provides satisfying color results: 1. Conversion to the RGB system LightTrans Colorsystem which was created by me, the author, based on the experiences with other color systems. It is defined by the colors of the three wavelengths 700 nm, 545 nm, and 470 nm as it s primaries and a white point of (w x, w y )= (0.3127, 0.3291) (which is equivalent to the color of a white surface illuminated by the so called standard illuminant D65). For development purposes (but maybe it will be released later) a di=erent color system can be chosen by the user. 2. These RGB values will be written into a bitmap (an instance of the Bitmap class provided by the company Aurigma (www.aurigma.com)), which got the monitor s color profile 3 assigned to. That means, the RGB values of the LightTrans Colorsystem are considered as being values in the monitor s color system. This consideration in turn means a special kind of gamut mapping (or rendering intent), with a one-to-one mapping of each triple (R LTC, G LTC, B LTC ) T to a triple (R mon, G mon, B mon ) T. The gamut of the LightTrans Colorsystem is shown in Fig. 4. 1 More precisely, the gamut is a three-dimensional solid in the XYZ space, whose projection gives the triangle. This is nicely illustrated on http://www.brucelindbloom.com/chromaticitygamuts.html. 2 For the conversion from one color system to another, called gamut mapping, exist several algorithms, called rendering intents, usually not treating only the outside lying colors in a special way, but converting the whole gamut instead! 3 If the monitor is not calibrated, see Sec. 4, a standard color profile will be used, possibly providing adulterated results. 7
3.2 Transformation Algorithm 1. At first, the matrix T in Eq.3.1 is calculated from the chromaticity coordinates of the RGB color space ((r x, r y ), (g x, g y ), (b x, b y ),and(w x, w y )) by the following steps: (a) (b) (c) (d) Calculation of the z components which are not independent from x and y: r z = 1 r x r y, g z = 1 g x g y, b z = 1 b x b y and w z = 1 w x w y Calculation of the matrix columns by the vectorial products x r g x b x =, y r z r x g y g z g x b y b z b = = g y g z b x b y b z r x r y r z b y b z r x r y r z g x g y g z, and Calculation of the white scaling factors w r x r y r z r w g = 1/w y x g y g z g w b x b y b z b The transformation matrix yields from: x r /w r y r /w r z r /w r T = x g /w g y g /w g z g /w g x b /w b y b /w b z b /w b w x w y w z 2. Using T in Equation (3.1) allows to calculate the values r, g or b for every color given as (x, y, z). 3. It can happen that one or more of the calculated values are negative. This means that the position of the color lies outside the RGB gamut (area inside the triangle, see Fig. 4), which in turn stands for the impossibility to represent this color in the RGB color space exactly. Please note: this is true for all monochromatic light sources! So in this case an important approximation called Out-of-gamut handling has to be done: Determine the intersection point of the line that connects the color coordinates and the white point with the sides of the gamut triangle. To use this point as substituting color means to keep the hue of the color while the saturation is set down to its valid range of 0..1 (spoken in terms of the HSV system). 8
4. In order to preserve the original luminosity, the value Y Σ has to be multiplied. Additionally, a simple Gamma correction 4 is applied (see the following subsection): r 1/γ ry Σ g = gy Σ b by Σ 5. At last a rescaling is necessary to get the usual value range of 0..255: R r G = g 255/ max(r, g, b ) B b 3.3 Gamma correction Whydowehavetoapplyagammacorrection? Thereasonisourgoalto simulate a virtual optics laboratory, i.e. the user shall have the same perception by looking at his monitor as by observing in the lab. But since computer monitors adapt to the non linear brightness sensitivity of the human eye, we have to "correct this correction". This is drafted in the following sketches: The human eye perceives a linear signal I S as a logarithmic function, which can be approximated by I P = I 1/γ S, γ 2: Figure 5. Computer monitors display linear signals using a function I M = I γ S,so the perceived intensity function will be approximately the input signal function: 4 The value of γ depends on the used color system. The most standard systems use γ = 2.2, some use 1.8. 9
Figure 6. In VirtualLab TM the signal will be prepared (I S = I1/γ S ), so that the monitor will display the original linear signal, which will be perceived as in the lab in turn: Figure 7. Note on the di=erent views of an electromagnetic field in VirtualLab TM : In consequence of the described gamma correction, the Light View will show a brightness distribution which (in comparison with the Data View) looks more like the Amplitude than like the Intensity. That s due to the fact that the data view doesn t use a gamma correction, so the intensity distribution of the Data View is more like the measurement result of a photometer, than like human perception. 10
4 Color Profiles and Monitor Calibration A color profile is a file that contains the definition of any color space or at least the data required for its transformation to a standard color space. It has to fulfill an ISO norm, published by the International Color Consortium (ICC Specification, see [ICC]. Usually, the individual color space of a device is stored in such a color profile, but also standard color spaces are communicated via that kind of files. We need it for telling the graphics card how to handle colors. Even a color that was converted to RGB correctly will not be displayed in the expected way if the monitor is not calibrated. Calibration means to set the device in a defined state and, most important, to determine the exact color profile for the monitor currently used. This device color space is defined by the chromaticities of the r, g, and b phosphors. The optimal way to calibrate a monitor is to measure the profile data by calibration software which uses a colorimeter and writes the resulting file to the appropriate directory (on Microsoft Windows systems: C:WINDOWS SYSTEM32 SPOOL DRIVERS COLOR). If chosen as standard color profile and if the startup program of the calibration software was started, the graphics card should use the profile for the correct display of the RGB colors on the monitor. 11
References [CIE32] Commission Internationale de l Eclairage Proceedings, Cambridge University Press, Cambridge, 1932 [CIE64] CIE Proceedings 1963 Vienna Session, Vol. B (Committee Report E- 1.4.1), Bureau Central de la CIE, Paris, 1964, pp. 209-220 [ICC] ISO 15076-1:2005, Image technology colour management Architecture, profile format and data structure Part 1: Based on ICC.1:2004-10 12