The RGB Code: The Mysteries of Color Revealed

Part 1: Cracking the RGB Color Code (from Light to XYZ)

By Danny Pascale

Dateline: November 8, 2004

The image was staring at our hero, as dead as an image can be. Not much to go on. Just the filename, summer2002-024.bmp, a not-so-cryptic name that reminded him of that summer of 2002 and the fun he had with his new digital camera, manipulating the images on his computer. However, the name was hiding something. The image looked wrong and it was flat, with non-saturated colors. And there were no hints, no EXIF metadata or embedded ICC profile, to help identify its origin, only bare RGB numbers.

An RGB number alone is like a home address without street and city names—mostly useless. You need to know its environment, where it came from, to better use it. There started our hero's quest to understand where these numbers came from and, hopefully, find the real image encrypted in these numbers.

The first part of this journey looks at how RGB numbers are derived (encoded) from the colors we perceive. This encoding involves other color codes which you will see in articles and magazines from time to time: xyz, xyY, XYZ. These, and others such as L*a*b*, Hex#, HSB and Munsell HVC, are all related in one way or another.

Cryptography is a complex science but, as in many cryptographic cases, you don't need to understand the mathematics to encode or decode data, you just need to know the secret key. However, when you don't have the key, you have just a few choices: the brute force approach (trying all combinations, a lengthy method indeed) or educated guessing (often quite efficient). The latter approach, educated guessing, involves some knowledge of what you're looking for. In this case, a basic understanding of what the mathematics do, not how they do it, is sufficient.

Color coding starts in the eye.

You may be surprised to learn that the eye of Horus, represented by the Egyptians thousands of years ago, is also a mathematical representation system in which each part of the symbol is equivalent to a given fractional number. Could the answer to the RGB code be embedded in the eye? And what about the strange relationship of some parts of this eye with other symbols discussed at length in recent best sellers such as… but we digress. Let's go back to our Real Good Basic science mystery.

A modern analysis of the human eye shows that it is generally composed of three sensor types that are sensitive to different electromagnetic wavelengths (i.e. colors). Each one is sensitive to quite a large color band and there is significant overlap between them. In effect, many single, pure (monochromatic), colors fall into more than one band, as shown below.

How we perceive color has to do with a mix of these signals at the eye level and how our brain processes that information. The result is that no two humans see colors the same way–even our left eye sees things differently than our right eye (and this is without considering common color deficiencies, such as the multiple forms of color blindness). Fortunately, we do typically agree with each other quite well.

Clue #1: The Standard Observer
This agreement on perceived color takes the form of the Standard Observers, a mathematical derivation extracted from perception tests performed on many subjects. Observers with an "s", as in many. In this case, two. A first Standard Observer was proposed in 1931 by the Commission Internationale de l'Éclairage (CIE).

It was derived from color patches subtending a 2 degrees Field Of View (FOV) with the eye, where the eye has its highest density of color sensors (color cones). This geometry corresponds well to color patches seen in images where many colors are seen next to one another. The computer graphics world is almost entirely based on the 2 degrees Observer.

In 1964, another Standard Observer was devised for color patches subtending a 10 degrees FOV with the eye; the CIE 1964 10 degrees Observer was thus born. This larger FOV encompasses almost all the eye's color sensors (the human eye is much less sensitive to color off-axis) and also more closely corresponds to the perception of large, uniformly colored expanses, such as wall or objects.

There is a definite relationship between the Standard Observers and the measured sensitivity of the eye sensors and it is amazing that the Standard Observers, based on perception, match quite well the physical microscopic measurements of the eye's sensors.

So here we have found the first element of our quest, a Standard Observer, a common base on which we can derive the color code.

Clue #2: The Illuminant
The perception of a color is influenced by the spectral content of the light source, the viewing environment (the color of the walls, for instance), the surface finish and your brain's memory.

If you compare a white sheet of paper held in front of a window at mid-day when there is a bright sun (not directly hitting the sheet of paper, though) with a similar sheet held nearby under a 60 Watt light bulb, so that you can simultaneously see both, the one under the light bulb will look much yellower. The brain part comes into effect when you look at these sheets separately at different moments; you'll vow that they are of the same white (give the brain a few seconds to adjust to its new environment). In this case the brain "knows" the sheet is white and forces itself to see it that way. This effect works for quite varying illumination conditions.

In comparison, colors will be perceived differently under various lights. Thus the importance of defining the light source, the Illuminant in colorimetry terms. Many standard Illuminants have been defined over the years. They are indicated by short descriptions, such as C (CIE Illuminant C), which stands for "North Sky Daylight, 6774 Kelvin", or D50, which stands for "Daylight 5000 Kelvin", which is commonly used for color rendering in graphic design applications. The Kelvin is a temperature unit for which 0 Kelvin is the absolute zero (equal to -273 degrees Celsius) and a one-Kelvin step is the same as a one-degree Celsius step. A 5000 Kelvin Illuminant has a spectrum which corresponds to the light emitted by a black body heated to this temperature (look at it as a calibrated chunk of metal with a hole from which light is emitted). As with the stars in the sky or forged metal, the hotter the temperature, the bluer it becomes. Illuminant D65, a very common Illuminant for computer screens, corresponds to a 6500 Kelvin temperature and is visibly bluer than D50.

Combining Our Clues: From Light to XYZ
We now have the two basic elements of color characterization: a Standard Observer and an Illuminant. These two combine to give us color coordinates. Here is the basic setup for color patches (a printed image) measured by reflection: A calibrated light is shone on a color sample. The measurement setup is usually configured in a geometry that minimizes the amount of light due to surface reflections (such as mirror effect or gloss). The diffused light falling on the detector is analysed in terms of the quantity of light falling within each band of the Standard Observer. The pro-rated quantities of light in each band are called XYZ, with X corresponding to the red region, and Y and Z corresponding to the green and blue regions (this process is shown below).

Y has a special additional meaning, having been defined in such a way that it corresponds to the measured luminance of the color, its grey level. This procedure is described in ASTM E308 (see Reference 1). Such a procedure, even though well explained in the ASTM document, is not trivial. Luckily, most modern colorimeters and spectrophotometers that we use to verify or calibrate our monitors and printers compute these three coordinates directly from their measurements. Alas, XYZ numbers are still not the RGB numbers our hero was looking for. The quest to RGB is not over yet, but at least we have a coding process which can bring us closer in deciphering the mysterious image numbers.

The next part of this series will describe how to get from XYZ to RGB and other color codes (or "color notations").


(1): ASTM E308: "Standard Practice for Computing the Colors of Objects by Using the CIE System," available from their Web site.

Don't miss the next installment of this series. Get the free newsletter in your mailbox each week. Click here to subscribe.

Danny Pascale: After many years of research and development, and project management work in the academic and industrial sectors, he now does technology assessment and helps companies bring new products to the market (a consultant, if you prefer!) in the computer and consumer electronics industries. He recently formed a new company, BabelColor, dedicated to the development of colorimetric software tools.