Mathematics of Human Color Perception
Our eyes are sensitive to a range of electromagnetic radiation oscillating faster than radio waves and microwaves, but slower than x-rays and gamma rays. The wavelength range of visible light is roughly 400 to 700 nanometers (nm) going from the violet end to the red end of the spectrum.
Generally, we can describe how an object appears to have a color as a four step process.
- The object is illuminated by a light source.
- The object selectively reflects light according to its reflectance properties.
- The reflected light, or stimulus, passes from the object and into our eyes.
- The stimulus is processed by our brain to give the impression of a colored object.
Let’s look at each step in more detail:
A light source has various levels of power at each frequency that can be summarized in a plot of relative power vs frequency, for example, as shown in the figure.
This is one of the “standard” illuminants used in colorimetric studies, called D65. It resembles daylight and is the reference illuminant for the sRGB color space (more on that later). Notice how it peaks more toward the blue end of the spectrum, making it a “cooler” light source than indoor incandescent illumination, which has much more power on the red end of the spectrum.
The reflectance properties of an object are conveniently summarized in a reflectance curve, which describes the fraction of incoming light that is reflected at each wavelength. This can be measured using a spectrophotometer. For example, the reflectance curve shown in the figure was measured from a bright red object.
Notice how this red sample reflects around 70% of the longer wavelengths, and very little of the shorter wavelengths.
Since reflectance is a fraction of reflected light, it falls in the range 0 to 1 at each wavelength. The only exception to this is with fluorescent objects, which can reflect more that 100% of incoming light at certain wavelengths, and therefore, have some reflectance values greater than 1.
To get the distribution of light that enters our eyes (the “stimulus“), we simply multiply the illuminant by the reflectance, as shown by the red curve in this figure.
The last step is to describe mathematically how our brain interprets a color stimulus, providing us with a color sensation. It can be described by a fairly simple matrix equation:
where, is the stimulus vector with values, is a 3x “color matching functions” matrix, is a 3×3 conversion matrix between “tristimulus values” and “linear RGB” values, is a normalizing factor that is related to the illuminant, and is the 3×1 RGB description of the color before gamma correction, or the “linear RGB” values.
The normalizing factor, , is simply the scalar product of the illuminant vector and the second row of . This makes the tristimulus value equal to 1 when the stimulus vector equals the illuminant. The handy thing about normalizing in this way is that the particular units of the stimulus vector no longer matter because they are cancelled out by the normalizing factor.
The tristimulus values, , , and are converted to linear rgb values through a linear transformation matrix, . There are many RGB color spaces, and each has its own RGB “primaries” and reference illuminant (or “white point”). In the case of the sRGB color space (which is referenced to illuminant D65), the matrix has the values shown here.
Note that I’m using the symbol here; the standard matrix is x3 instead of 3x, and so indicates that it has been transposed.
This can be further simplified for the special case of obtaining linear RGB values, , directly from a reflectance curve, . The , , and terms can all be combined together ahead of time into a single matrix, . Furthermore, since is the product of the illuminant and the reflectance curve, , the illuminant can be extracted from and also be combined into the matrix, leaving only the reflectance curve behind:
where is a vector of reflectance values in the range 0 to 1.
The size of and the length of depend on how finely we measure the reflectance curve. Typically, it is measured every 10 nm in the range 380 nm to 730 nm, making a 3×36 matrix and a 36×1 vector. Here are the specific values for the matrix (again, for the special case of D65-referenced linear RGB calculation from a reflectance curve).
=MMULT(T_array,rho_vector)and press ctrl-shift enter).
The final step to get true sRGB values from the linear RGB values is to apply a type of gamma correction, also known as “companding” or applying the “color component transfer function.” This process will be familiar to anyone using the Levels function in Photoshop, when moving the middle Levels control. The sRGB companding action compresses higher values of RGB and expands lower values, giving a more pleasing and realistic-looking sRGB color space.
=IF(v<0.0031308, 12.92*v, 1.055*v^(1/2.4)-0.055). The result of this will be true sRGB values in the range 0 to 1. Multiply them by 255 and round to the nearest integer to get the alternate range of 0 to 255, as used in Photoshop for example (in Excel:
=ROUND(255 * IF(v<0.0031308, 12.92*v, 1.055*v^(1/2.4)-0.055), 0)). More information on this conversion process can be found at Bruce Lindbloom's highly informative website.
Thus, we now have a way to compute an sRGB triplet given a particular reflectance curve, . For the purposes of subtractive color mixture of two sRGB colors, if we know the reflectance curves corresponding to the two sRGB colors, we can perform the subtractive mix on the reflectance curves to arrive at another reflectance curve, and then compute the sRGB values from the mixture reflectance using the equation above. How is the subtractive mix of reflectances achieved? This is discussed next.
The presentation is spread over several web pages. Click the Next Page or Previous Page links to move sequentially. To access a page directly, use these links:
2. Mathematics of Human Color Perception (this page)
3. Subtractive Mixture of Two Reflectance Curves
4. Cataloged Reflectance Curves
5. Computing Reflectance Curves Directly from sRGB Values