Colour Quiz Homepage
The page contains mathematical symbols and Greek letters, and some letters from the extended Latin ISO-8859-1 character set. If these do not show correctly, then
What is wrong with this?
The above is supposed to show, as accurately as possible on a computer screen, the colours of the visible spectrum as a function of wavelength in nanometers. What is wrong with it? The problem is that computer monitors cannot show monochromatic colours as saturated as the eye is able to perceive them. Disco purple, at the shortest monochromatic wavelengths, probably shows up on the screen as wilting violet, while crimson red, at the longest monochromatic wavelengths, appears pinkish.
How do you plot a spectrum of monochromatic colours as accurately as possible on a computer screen? Set saturation to 1, and run hue from -0.046 (i.e. 0.954, about right for crimson red) to 0.753 (about right for disco purple), right? Actually it's more complicated if you want to do it right. The following four steps describe what to do.
Step 1: Define the spectrumAs you undoubtedly know, the eye perceives colour through three types of cone on the retina. As a result, it is possible to define any colour, any mixture of visible wavelengths, using 3 coordinates.
By convention of the Commission Internationale de l'Éclairage (CIE), colours are defined by their `tristimulus' coordinates X, Y, Z. The coordinates are linear measures of light power, so that the coordinates of any sum of colours is the sum of the coordinates of the colours. The middle coordinate, Y, called the `luminance', is the light power weighted by the CIE 1924 Photopic Luminosity Function, a certain spectral sensitivity function characteristic of human vision. The luminance Y can be regarded as a measure of perceived brightness, with the proviso that it varies linearly with power, whereas the eye responds nonlinearly with power.
A table of the tristimulus coordinates X, Y, Z for monochromatic light every 1 nm from 360 nm to 830 nm is available from the UCSD Color and Vision database. There are two sets of files, the original 1931 set, based on experiments that involved people matching colours in a split 2° field, about the size of the cone-rich fovea at the center of the retina, and a supplementary 1964 set, for a 10° field, which gives greater weight to rods. The 2° tristimuli are appropriate for normal colour vision at daylight levels of illumination, while the 10° tristimuli are more appropriate for dark-adapted vision. The spectrum at the top of this page used the 2° field tristimuli.
Step 2: Define the characteristics of the monitorThe characteristics of a colour monitor are determined by the the colours of its guns, its red, green, and blue primaries. Measured on a linear scale of light power, the monitor's primaries are denoted R, G, and B. It is important to distinguish these linear measures of colour from the nonlinear measures R¢, G¢, B¢ that are specified to the computer's colour tables. More on the latter in Step 4 below.
The colour of each primary is specified by its tristimulus coordinates. For example, the colour of the R gun is specified by XR , YR , ZR . Given these coordinates, the tristimulus coordinates X, Y, Z of any combination colour R, G, B are given by the linear transformation
Conversely, the R, G, B coordinates of any colour X, Y, Z are given by the inverse of the matrix transformation (2).
Usually, the colour properties of a monitor are specified not in terms of the tristimuli of its primaries, as above, but rather in terms of the chromaticities xR , yR , xG , yG , xB , yB , of the primaries, together with the chromaticity xW , yW of the white point. Conventionally, the luminance of white is normalized to one, YW = 1. The 6 primary chromaticities, the 2 white chromaticities, and the white luminance together constitute 9 quantities, precisely sufficient to specify the 9 tristimulus coordinates of the R, G, B primaries.
What primary and white chromaticities should one assume? Item 45 of the Color FAQ recommends using the CIE D65 `daylight' white point
Step 3: Transform from XYZ to RGBGiven the tristimuli coordinates X, Y, Z of any colour, such as those for monochromatic colours specified in the CIE 2° tables, and the characteristics of the colour monitor as described in Step 2, the corresponding R, G, B coordinates follow from equation (3).
Often one or two (never three) of the R, G, B coordinates will turn out negative. This means that the colour lies outside the `gamut' of colours that the monitor can reproduce. For example, every monochromatic colour is out of gamut. On the chromaticity diagram, the gamut forms a triangle with the monitor's primaries at its vertices, as in the diagram on the right, constructed using a corrected version of John Walker's cietoppm utility. The blackbody trajectory on this chromaticity diagram is discussed on the What colour is the Sun? page. Compare this diagram to the chromaticity diagram with respect to the fundamental primaries on the Primary Colours page.
The standard way to fix out-of-gamut colours is to add white - equal parts of R, G, and B - just enough to make all components positive, so bringing the colour to the border of the gamut. That is, add -min(R, G, B, 0) to each of R, G, and B. It is this adding of white that causes disco purple and crimson red to appear palid in the spectrum at the top of this page.
At this point you are free to multiply the R, G, and B values of your entire picture by some overall factor, to achieve the desired overall level of brightness. If any of the R, G, or B values exceed the permitted maximum (typically 1, or 255), then obviously you will have to scale those values back to the maximum.
Step 4: Do a gamma correctionThe colour guns on monitors respond nonlinearly to their inputs. As Charles Poynton emphasizes in Gamma FAQ, this is a feature, not a bug. The nonlinearity roughly matches the nonlinear response of the human eye, and allows a broader dynamic range of perceived brightnesses to be coded with fewer bits.
The transformation from linear coordinates R, G, and B to nonlinear coordinates R¢, G¢, and B¢, or vice versa, is called `gamma-correction'. It is the latter nonlinear coordinates R¢, G¢, B¢ that are specified in software, such as in HTML, PostScript, xv, and so on.
Colour Quiz Homepage
Updated 18 Nov 1999