Color matching

Applet: Nora Willett
Text: Marc Levoy
Technical assistance: Andrew Adams

In our introduction to color theory, we showed that for a given choice of three primary colors, one can record the amount of each primary required to visually match each color in the rainbow. We also said that this record can be plotted as three curves, which are called the "trichromatic matching functions". This matching experiment was first undertaken in the 1850's by James Clerk Maxwell (of Maxwell's equations fame). His experiment consisted of trying to match a patch of white light using an additive superposition of three single-wavelength primaries. The color of one primary was made to vary through the rainbow over a sequence of trials. The color of the other two were fixed, but the user was free to adjust their intensities on each trial to achieve a match against the white patch. In this applet we explore a common variant on this experiment, in which we try to match a patch of color whose wavelength varies through the rainbow. At our disposal are three primary colors whose wavelengths are fixed, but whose intensities we may adjust on each trial to match the changing patch.

Trying to match a given color

In the applet above, the "Target Color" is the patch we must match. Using the slider at lower-right labeled "Lambda", you can change the color of this patch from deep blue at a wavelength of 400 nanometers to deep red at a wavelength of 700 nanometers. The primaries at our disposal are depicted on the left side. Like the Target Color they are single-wavelength colors from the rainbow, with wavelengths of 612nm, 525nm, and 445nm. If you move the slider for one of these primaries to the right, you are adding that much of the primary to the patch labeled "Color Match". With the Target Color in its "Reset" position of 405nm, this task is easy; a bit of the blue primary (445nm) does the job.

For a more challenging color, move the Target Color slider to 600nm (watch the yellow balloon popup), and try to match that color (a bright orange). Struggling? Click on "Hint"; an arrow will pop up showing you which primary you should tweak, and in which direction. Give up? Click on "Answer" to see the right answer. (If you're colorblind, all bets are off - you'll get good matches for some target colors, but random matches for others.)

Ok, here's the Boss Level. Move the Target Color slider to 500nm and try to match that color (a greenish shade of aquamarine). You'll find it impossible. Go back to the second applet on the Introduction to Color Theory page [link], click on "show gamut" and "show tic marks", and spin the 3D colorspace until the lines denoting the green and blue primaries line up (or fall atop one another). Additive mixture of green and blue are capable of matching any color on the plane formed by these two lines. Note how the locus bows out to the right. The 500nm tick mark is part of this bow. This means that no mixture of green and blue can match this color. Note also that the line representing the red primary extends to the left from this green-blue alignment. This means that adding red will make the situation worse, not better. Given the closest match you can make using green and blue, you could reach the 500nm tick mark if you could move parallel to the red line, but in the negative (rightward) direction. This is physically impossible, since it requires negative light, so in the matching experiment we ad a bit of red to the test stimulus, thereby moving it from the position of the 500nm tick mark leftward. This movement desaturates the stimulus, eventually bringing it to the green-blue plane. At this point we can match it using only a mixture of green and blue.

Returning to the applet above, you can apply this trick by moving the slider controlling the red primary to the left. Note that this motion slightly desaturates the Target Color. Can't find the right mix? Click on "Answer". Once you get the hang of it, you can march the Target Color from color to color, adjusting the three sliders to find a match. Impatient? Click on "Show Curves". This displays the correct positions of the three sliders for every wavelength in the rainbow. These are the trichromatic matching functions for these particular primaries. As mentioned in the introductor applet, one could choose a different set of primaries, obtaining a different set of matching functions.

How is this applet implemented?

Most computer screens these days are liquid crystal displays (LCD). Color is produced on these LCDs by placing red, green, or blue filters over adjacent pixels in a pattern that repeats hundreds or thousands of times across the screen. These filters are not "spectral notches", meaning that the light they transmit is not a single wavelength. In fact, their spectral power distributions (SPD) are broad and overlapping. Thus, the colors one can produce using a computer screen don't lie on the locus of spectral colors, but well inside this locus.

If this is true, then how can we write an applet that purports to give you a single-wavelength test stimulus and three single-wavelength primaries? Well, we can't. What we've done to make this applet work is set the colors in the rainbow (below the matching functions graph) to the tristimulus sensitivity functions, i.e. (R(lambda), G(lambda), B(lambda)) = (rho(lambda), gamma(lambda), beta(lambda)). In other words, as you march through each wavelength in the rainbow, the Target Color takes on the coordinates of each point on the locus of spectral colors relative to the three axes rho, gamma, and beta in 3D colorspace [link to first color applet].

By construction, the correct Color Match for each wavelength will then be the coordinates of this point on the locus relative to the red, green, and blue primary axes in colorspace. These are of course the trichromatic matching functions for these primaries. In summary, we have used the geometry of 3D colorspace to ensure that the matches you work out for each Target Color follow the Trichromatic Matching Functions, even though the color being displayed may be inaccurate for that wavelength.

To improve on this implementation, we could seek for each wavelength on the slider a color from the physical gamut of your LCD that looks perceptually closest to the indicated single-wavelength color. However, that's more work, and the current solution seems good enough. It's a cheap mathematical trick we've played on you, but it's a straightforward way to visualize Maxwell's color matching experiment without requiring pure spectral colors to perform the matching.