1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Colorspaces</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="LINUX MEDIA INFRASTRUCTURE API"><link rel="up" href="pixfmt.html" title="Chapter&#160;2.&#160;Image Formats"><link rel="prev" href="ch02s03.html" title="Standard Image Formats"><link rel="next" href="ch02s05.html" title="Defining Colorspaces in V4L2"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Colorspaces</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch02s03.html">Prev</a>&#160;</td><th width="60%" align="center">Chapter&#160;2.&#160;Image Formats</th><td width="20%" align="right">&#160;<a accesskey="n" href="ch02s05.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="colorspaces"></a>Colorspaces</h2></div></div></div><p>'Color' is a very complex concept and depends on physics, chemistry and
2biology. Just because you have three numbers that describe the 'red', 'green'
3and 'blue' components of the color of a pixel does not mean that you can accurately
4display that color. A colorspace defines what it actually <span class="emphasis"><em>means</em></span>
5to have an RGB value of e.g. (255,&#160;0,&#160;0). That is, which color should be
6reproduced on the screen in a perfectly calibrated environment.</p><p>In order to do that we first need to have a good definition of
7color, i.e. some way to uniquely and unambiguously define a color so that someone
8else can reproduce it. Human color vision is trichromatic since the human eye has
9color receptors that are sensitive to three different wavelengths of light. Hence
10the need to use three numbers to describe color. Be glad you are not a mantis shrimp
11as those are sensitive to 12 different wavelengths, so instead of RGB we would be
12using the ABCDEFGHIJKL colorspace...</p><p>Color exists only in the eye and brain and is the result of how strongly
13color receptors are stimulated. This is based on the Spectral
14Power Distribution (SPD) which is a graph showing the intensity (radiant power)
15of the light at wavelengths covering the visible spectrum as it enters the eye.
16The science of colorimetry is about the relationship between the SPD and color as
17perceived by the human brain.</p><p>Since the human eye has only three color receptors it is perfectly
18possible that different SPDs will result in the same stimulation of those receptors
19and are perceived as the same color, even though the SPD of the light is
20different.</p><p>In the 1920s experiments were devised to determine the relationship
21between SPDs and the perceived color and that resulted in the CIE 1931 standard
22that defines spectral weighting functions that model the perception of color.
23Specifically that standard defines functions that can take an SPD and calculate
24the stimulus for each color receptor. After some further mathematical transforms
25these stimuli are known as the <span class="emphasis"><em>CIE XYZ tristimulus</em></span> values
26and these X, Y and Z values describe a color as perceived by a human unambiguously.
27These X, Y and Z values are all in the range [0&#8230;1].</p><p>The Y value in the CIE XYZ colorspace corresponds to luminance. Often
28the CIE XYZ colorspace is transformed to the normalized CIE xyY colorspace:</p><p>x = X / (X + Y + Z)</p><p>y = Y / (X + Y + Z)</p><p>The x and y values are the chromaticity coordinates and can be used to
29define a color without the luminance component Y. It is very confusing to
30have such similar names for these colorspaces. Just be aware that if colors
31are specified with lower case 'x' and 'y', then the CIE xyY colorspace is
32used. Upper case 'X' and 'Y' refer to the CIE XYZ colorspace. Also, y has nothing
33to do with luminance. Together x and y specify a color, and Y the luminance.
34That is really all you need to remember from a practical point of view. At
35the end of this section you will find reading resources that go into much more
36detail if you are interested.
37</p><p>A monitor or TV will reproduce colors by emitting light at three
38different wavelengths, the combination of which will stimulate the color receptors
39in the eye and thus cause the perception of color. Historically these wavelengths
40were defined by the red, green and blue phosphors used in the displays. These
41<span class="emphasis"><em>color primaries</em></span> are part of what defines a colorspace.</p><p>Different display devices will have different primaries and some
42primaries are more suitable for some display technologies than others. This has
43resulted in a variety of colorspaces that are used for different display
44technologies or uses. To define a colorspace you need to define the three
45color primaries (these are typically defined as x,&#160;y chromaticity coordinates
46from the CIE xyY colorspace) but also the white reference: that is the color obtained
47when all three primaries are at maximum power. This determines the relative power
48or energy of the primaries. This is usually chosen to be close to daylight which has
49been defined as the CIE D65 Illuminant.</p><p>To recapitulate: the CIE XYZ colorspace uniquely identifies colors.
50Other colorspaces are defined by three chromaticity coordinates defined in the
51CIE xyY colorspace. Based on those a 3x3 matrix can be constructed that
52transforms CIE XYZ colors to colors in the new colorspace.
53</p><p>Both the CIE XYZ and the RGB colorspace that are derived from the
54specific chromaticity primaries are linear colorspaces. But neither the eye,
55nor display technology is linear. Doubling the values of all components in
56the linear colorspace will not be perceived as twice the intensity of the color.
57So each colorspace also defines a transfer function that takes a linear color
58component value and transforms it to the non-linear component value, which is a
59closer match to the non-linear performance of both the eye and displays. Linear
60component values are denoted RGB, non-linear are denoted as R'G'B'. In general
61colors used in graphics are all R'G'B', except in openGL which uses linear RGB.
62Special care should be taken when dealing with openGL to provide linear RGB colors
63or to use the built-in openGL support to apply the inverse transfer function.</p><p>The final piece that defines a colorspace is a function that
64transforms non-linear R'G'B' to non-linear Y'CbCr. This function is determined
65by the so-called luma coefficients. There may be multiple possible Y'CbCr
66encodings allowed for the same colorspace. Many encodings of color
67prefer to use luma (Y') and chroma (CbCr) instead of R'G'B'. Since the human
68eye is more sensitive to differences in luminance than in color this encoding
69allows one to reduce the amount of color information compared to the luma
70data. Note that the luma (Y') is unrelated to the Y in the CIE XYZ colorspace.
71Also note that Y'CbCr is often called YCbCr or YUV even though these are
72strictly speaking wrong.</p><p>Sometimes people confuse Y'CbCr as being a colorspace. This is not
73correct, it is just an encoding of an R'G'B' color into luma and chroma
74values. The underlying colorspace that is associated with the R'G'B' color
75is also associated with the Y'CbCr color.</p><p>The final step is how the RGB, R'G'B' or Y'CbCr values are
76quantized. The CIE XYZ colorspace where X, Y and Z are in the range
77[0&#8230;1] describes all colors that humans can perceive, but the transform to
78another colorspace will produce colors that are outside the [0&#8230;1] range.
79Once clamped to the [0&#8230;1] range those colors can no longer be reproduced
80in that colorspace. This clamping is what reduces the extent or gamut of the
81colorspace. How the range of [0&#8230;1] is translated to integer values in the
82range of [0&#8230;255] (or higher, depending on the color depth) is called the
83quantization. This is <span class="emphasis"><em>not</em></span> part of the colorspace
84definition. In practice RGB or R'G'B' values are full range, i.e. they
85use the full [0&#8230;255] range. Y'CbCr values on the other hand are limited
86range with Y' using [16&#8230;235] and Cb and Cr using [16&#8230;240].</p><p>Unfortunately, in some cases limited range RGB is also used
87where the components use the range [16&#8230;235]. And full range Y'CbCr also exists
88using the [0&#8230;255] range.</p><p>In order to correctly interpret a color you need to know the
89quantization range, whether it is R'G'B' or Y'CbCr, the used Y'CbCr encoding
90and the colorspace.
91From that information you can calculate the corresponding CIE XYZ color
92and map that again to whatever colorspace your display device uses.</p><p>The colorspace definition itself consists of the three
93chromaticity primaries, the white reference chromaticity, a transfer
94function and the luma coefficients needed to transform R'G'B' to Y'CbCr. While
95some colorspace standards correctly define all four, quite often the colorspace
96standard only defines some, and you have to rely on other standards for
97the missing pieces. The fact that colorspaces are often a mix of different
98standards also led to very confusing naming conventions where the name of
99a standard was used to name a colorspace when in fact that standard was
100part of various other colorspaces as well.</p><p>If you want to read more about colors and colorspaces, then the
101following resources are useful: <a class="xref" href="bi01.html#poynton" title="Digital Video and HDTV, Algorithms and Interfaces">[<abbr class="abbrev">poynton</abbr>]</a> is a good practical
102book for video engineers, <a class="xref" href="bi01.html#colimg" title="Color Imaging: Fundamentals and Applications">[<abbr class="abbrev">colimg</abbr>]</a> has a much broader scope and
103describes many more aspects of color (physics, chemistry, biology, etc.).
104The <a class="ulink" href="http://www.brucelindbloom.com" target="_top">http://www.brucelindbloom.com</a>
105website is an excellent resource, especially with respect to the mathematics behind
106colorspace conversions. The wikipedia <a class="ulink" href="http://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_xy_chromaticity_diagram_and_the_CIE_xyY_color_space" target="_top">CIE 1931 colorspace</a> article
107is also very useful.</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch02s03.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="pixfmt.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="ch02s05.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Standard Image Formats&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;Defining Colorspaces in V4L2</td></tr></table></div></body></html>
108