What is a color?
We have known for hundreds of years that visible light is a combination of many different colors. Different colors
in the visible spectrum correspond to distinct wavelengths of light, ranging from about 380 nanometers to about 780
nanometers.
A color can be described as a mixture of all the colors in the spectrum multiplied by a spectral intensity
distribution.
Sensitivity of cones
The human visual visual system is a tri-chromatic system. The human retina contains three different kinds of cone
cells that respond to different wavelengths of visible light.
1
LMS color space
One way to characterise a particular color is by measuring how strongly that color's spectral distribution makes the
various cone cell types respond.
I(λ) l(λ)d λ
L =∫
780
380
M
=∫
780
380
( ) ( )d λ
I λ m λ
= ∫ I(λ) s(λ)d λ
This makes it possible to associate a color with a point in LMS color space, which is a three-dimensional vector
space of color values.
One practical problem with this approach is that it is very difficult to measure the response of the cones in the
human visual system to particular distributions of light spectra. In principle we could compute the response curves
for each of the three cone types and compute L, M, and S components as shown above.
S
780
380
Wright and Guild color matching experiments
Long before it become possible to construct accurate response curves for the cone cells in the human retina, Wright
and Guild performed a series of experiments that indirectly measured the function of the human visual system by
asking volunteers to perform a color matching task. In their experiments volunteers would be shown a test color and
would be asked to approximate that color by combining varying intensities of red, green, and blue light from
standardized light sources.
2
From the experimental data that they gathered, Wright and Guild were able to construct matching curves for their
three color system.
Given a spectral distribution for a particular target color, I(λ), these matching curves would make it possible to
3
recover the R, G, and B settings the experimental subjects would use to reproduce the target color.
R=∫
I(λ) r(λ)d λ
780
380
G
=∫
780
380
( ) ( )d λ
I λ y λ
= ∫ I(λ) z(λ)d λ
These three values would make it possible to organize the set of all possible colors into a three-dimensional vector
space with coordinates R, G, and B.
One peculiarity of the matching curves they developed was the fact that the matching curve for red could take on
negative values. Wright and Guild's experiments allowed for the concept of negative color, in that subjects could
construct target colors
T(λ) = - R r(λ) + G g(λ) + B b(λ)
by adding the red contribution to the target color instead of subtracting it from the other colors:
T(λ) + R r(λ) = G g(λ) + B b(λ)
780
B
380
rg Chromaticity space
On complication of color spaces such as LMS and RGB is that they are three dimensional, which makes them
difficult to visualize. One relatively straight-forward way to reduce color space from three dimensions down to two
is to factor out intensity. If consider the set of all points in RGB space for which R + G + B = V, we will obtain a
subset of colors with common intensity. We can move around in this two dimensional subset by defining
coordinates
R
r=
R+G+B
g
= R + GG + B
In this coordinate system we do not need a blue coordinate, since blue can always be computed from the other two
colors.
B
b=
=1-r-g
R+G+B
Here is a chromaticity diagram showing the set of all colors with a common intensity. The colors of the spectrum
are arrayed around the perimeter of the diagram.
4
CIE XYZ color space
One problem with the RGB color system outlined above is that some colors will require negative coordinates to
express. We can eliminate this problem by means of a change of basis.
0.49 0.31 0.20 R
X
1 0.17697
Y =
0.01063 G
0.17697 0.00 0.81240
Z
0.01 0.99 B
In the resulting XYZ color space all colors can be expressed as a combination
XC +YC +ZC
where the colors C , C , and C are imaginary colors located a specific locations in the RGB color space. In the
XYZ color space the coordinates X, Y, and Z will always be guaranteed to be positive.
The XYZ color space described here was released as an international standard, the CIE 1931 2 color space. This
color standard forms a standard reference point for all other color spaces.
r
r
g
g
b
b
o
CIE color matching functions
5
The change of basis described above has the additional side effect of adjusting the color matching functions.
As before, we can use these color response functions to compute X, Y, and Z coordinates from the spectral intensity
distribution I(λ) of a color.
X=∫
I(λ) x(λ)d λ
780
380
Y
=∫
780
Z
=∫
780
380
380
CIE chromaticity diagram
( ) ( )d λ
I λ y λ
( ) ( )d λ
I λ z λ
As above, we can plot the set of all colors in XYZ space for which X + Y + Z = V by introducing coordinates
X
x=
X+Y+Z
y
z
= X + YY + Z
= X + ZY + Z = 1 - x - y
The plot of all colors in this color subspace gives us the CIE 1931 color space chromaticity diagram.
6
Relationship of XYZ space to RGB space
Just as we can use a linear transformation to map RGB space to XYZ space, we can use a transformation to map
XYZ space back to RGB space. In fact, we can map XYZ to many alternative RGB color spaces simply by picking
different points in the chromaticity diagram to play the role of the red, green, and blue colors.
7
Rec 709 RGB space
Another widely used RGB color space is the Rec 709 RGB color space. This is a color space standard that is used
for HDTV broadcasts. The red, green, and blue color points in this space are chosen to be colors that can be
generated by using the red, green, and blue phosphors on a standard HDTV display.
8
Gamut of a device
Most modern display devices produce colors by combining red, green, and blue colors. The precise colors that each
device uses for red, green, and blue will differ slightly from one device to the next. The set of all colors a given
device can produce by combining these colors lies in the triangle in the chromaticity diagram bounded by these
three colors. This range of reproducible colors for the device is known as the gamut of that device.
9
Gamma correction
Another important fact about the human visual system is that it responds in a non-linear way to the intensity of
light. We can see this most clearly by making a table of various intensities of white light. In the table below, the
color GrayV is the color (V/100,V/100,V/100) in RGB color space.
10
If you ask most human observers to pick the shade of gray that is half way between black and white, they will pick
Gray20 as being halfway between black and white, even though in intensity terms Gray20 is only 20% of the way
from black to white. This peculiar choice comes about because the human visual system is more sensitive to
intensity gradations at the low intensity end of the scale and correspondingly less sensitive to intensity gradations at
the upper end of the scale. You can also see that effect at work by noting that most human observers will say that
there is much more variation between Gray05 and Gray15 than between Gray85 and Gray95, even though both
sequences represent the exact same variation in intensity.
In order to begin to capture this non-linearity of sensitivity to intensity changes, we can apply a mathematical
transformation to the V levels in the diagram above in an effort to map V/100 = 0.20 much closer to 0.50, so that
Gray20 can take its place in near the center of the perceived intensity scale. One simple way to achieve this
mapping is to use a gamma encoding:
I = (V/100)
By selecting the appropriate exponent γ we can map the actual V/100 = 0.20 to the desired I = 0.5. As the diagram
below shows, using γ = 1/2.2 does the trick.
γ
11
This transformation is also reversible, in that we can recover V from I by doing
V=I
100
This transformation also has the desirable side effect of mapping the range of V from 0 to 20, where humans
perceive a lot of variation, to a broader range I = [0.0,0.5]. Likewise, the mapping compresses the range V =
[20,100], where humans perceive less variation, down to a smaller range I = [0.5,1.0].
2.2
Gamma encoding makes it possible to pack more useful information into a limited number of bits, especially in
applications where we only have 8 bits per color available to encode color values. Gamma encoding becomes less
critical when we have more bits available to represent color information.
sRGB color space
12
Given the non-linear nature of color perception, it makes sense to combine gamma encoding into a color space. One
such color space is the widely used sRGB color space.
The first step in computing an sRGB color coordinate is to transform the color from CIE 1931 XYZ space to a
linear RGB color space.
R
3.2406 -1.5372 -0.4986
G
= -0.9689 1.8758 0.0415 XY
0.0557 -0.2040 1.0570 Z
B
linear
linear
linear
The linear RGB values are subsequently gamma encoded via a gamma-like transformation
R
R
≤ 0.0031308
R
= (1 + 0.05512.92
- 0.055 R > 0.0031308
)R
{
sRGB is used as the color encoding standard in a number of applications, such as JPEG and MPEG image
compression. Also, many cameras automatically encode picture data in an sRGB format. sRGB encoding is also the
standard color space for HTML.
linear
sRGB
linear
1/2.4
linear
linear
sRGB and OpenGL
OpenGL uses a floating point linear RGB representation internally for all color computations. In this representation
a color is represented as a triple (r, g, b) with each coordinate represented by a float in the range from 0.0 to 1.0.
Since a float is a 32 bit data type with 8 decimal digits of precision, gamma encoding is not necessary to make the
most effective use of the color space.
OpenGL is capable of using both sRGB and RGB encoded textures. The color format used for the input colors from
a texture are specified in the third parameter to glTexImage2D.
glTexImage2D(GL_TEXTURE_2D, level, GL_SRGB, texWidth, texHeight, 0,
GL_RGB, GL_UNSIGNED_BYTE, &pixData[0]);
You must take care to specify GL_SRGB for this third parameter if the input image is encoded in sRGB. If you
specify GL_RGB for the third parameter instead, OpenGL will not decode gamma encoded values and your image
will appear to be too bright.
Likewise, from version 3.0 OpenGL allows you to specify either RGB or sRGB as the encoding format for
framebuffers.
13
© Copyright 2026 Paperzz