[Math] Color space as a vector space

vector-spaces

I am not sure that this is the best place for this topic, so I apologize in advance.

I have two questions. I think that color space with say additive colors (red, green, blue) forms a vector space. The colors add and there are inverses. First: One issue is that each possible color is a linear combination of some normalized amount of each of the basis colors (even if the overall "vector" is not normalized). Each red, green, and blue saturate; there is the concept of a color being maximally but finitely blue. And I can add pure (that is maximal) red to pure (maximal) blue and get an intense and even purple (I think maximal), but I would not have that vector (1, 0, 1) normalized. Is there a concept for this – where each coefficient for a basis is bounded? They do not really form a field, so it technically is not a vector space. I cannot keep on adding red without maxing out. But it is something really close. What is my space called? Second: In the standard hex system of representing RGB colors on a computer, what is the 0 'vector'? What is .1 red + .1 antired? Is this 0 the same color regardless of system (including switching from light (additive) to pigment (subtractive)), even if the representation changes?

I hope that these questions make some sense and are appropriate for this forum. If the latter condition is untrue, can you direct me to the proper place?

Best Answer

You have a lot more than two questions :)

Colorspaces are esoteric — you might find other insights in the photography or video Stack sites, nevertheless color science is one of my specialties, so I'll address some of these questions.

COLORSPACES - The Primal Frontier

I am going to assume you are referring to sRGB, the standard colorspace for computer monitors and the web. It is closely related to Rec709, the colorspace for HDTV. Rec709 and sRGB have identical reg, green, blue primaries and identical white point, but they have a different TRC (transfer curve, sometimes referred to as gamma). Neither sRGB nor Rec.709 are linear as both are encoded with a piecewise TRC, for Rec709 the TRC is roughly equivalent to a power function with a 1/2.0 exponent, and sRGB is roughly 1/2.2

The monitor/TVset has an inverse TRC when displaying the signal.

sRGB is normally sent to the monitor in the form of 3 channels, Red, Green, and Blue. These are independent but you can form a cube with them and use cartesian coordinates, though in practice that is not necessarrly useful with sRGB.

Rec709 is commonly encoded as "4:2:2" and I'll explain that in a moment, but first:

Modeling Light and Perception

CIEXYZ 1931

$X\ YZ$ is another colorspace, the "granddaddy" of colorspaces you might say. It also uses "red green blue" primaries, however they are imaginary, and do not exist in reality. XYZ is device independent, it does not relate to a monitor nor a camera.

XYZ is based on a series of experiments in color perception carried out between 1924 and 1931. XYZ uses experimental data from a small group of people, mapping the gamut of human vision into a cartesian space.

Instead of being based on a device like a camera or printer or monitor, it is based around the aggregation of the experimental data, creating a "standard observer".

$Y$ is luminance, which is the light/dark of a color irrespective of hue or saturation. Luminance may be denoted as $L$ when it is an absolute measure of light, in cd/m2. Luminance $Y$ is a normalized relative value of 0 to 1 (sometimes scaled 0 to 100).

Luminance is a linear measure of light and it is not perceptually uniform relative to human visual perception of lightness/darkness/brightness. Luminance is however spectrally weighted based on our perception of different wavelengths of visible light. The $x$ and $y$ (lowercase) provide coordinates for this chromaticity diagram, the outer bounds of which are the spectral locus. $xyY$:

CIE 1931 Chromaticities Diagram
$CIE\ \mathit{1931}\ Chromaticities\ Diagram\ (xyY,\ Y\ not\ shown)$

Human perception is non-linear. Human vision between 8cd/m2 and 520cd/m2 follows a power curve with an exponent of 0.42 (roughly).

So, if modeling the behavior of light, then use luminance and linear math (to triple the quantity of light, multiply by 3, etc.). But if modeling the human perception of changes in light quantity, luminance needs to be transformed to a value that is linear to perception instead of linear to physical light.

CIELAB $L^*a^*b^*$

(Not to be confused with SeaLab...)

Another colorspace, CIELAB in 1976 is derived from the 1931 XYZ, but $L^*a^*b^*$ is intended to be perceptually uniform, so that a perceptual change in lightness or color can be measured as the euclidian distance from another color, and that distance is "roughly" the same for the given amount of perceived change for small color differences. (Not that accurate for some larger distances).

The simple difference is: $$ ∆E = \sqrt {\left( {L_1^*} - {L_2^*} \right) + \left({a_1^*} - {a_2^*} \right) + \left({b_1^*} - {b_2^*} \right)} $$

Here, $L^*$ is perceptual lightness, relative to the way we perceive light. the $a^*$ and $b^*$ are based on the opponent/unique colors of Red/Green ($+a^*$ is Magenta $-a^*$ is Green) and Yellow/Blue ($+b^*$ is Yellow, $-b^*$ is Blue).

$L^*a^*b^*$ is based on the opponent color aspect of human vision. While you can measure the difference via the straight line between two points, the average of two colors does not necessarily lie on that line. This brings us to another space also from 1976, CIELUV.

CIELUV $L^*u^*v^*$

$L^*u^*v^*$ uses the same $L^*$ as LAB, but the $u^*v^*$ are based on coordinates of the 1976 UCS chromaticity diagram, which is a "slightly more uniform" projection of the 1931 diagram.

enter image description here
$CIE\ \mathit{1976}\ UCS\ Diagram\ (uʹvʹ)$

An advantage with $L^*u^*v^*$ is that the average of two lights lies on the line between the two points in space representing those lights, per Grassmann's laws of light additivity.

The color difference equation for LUV is the same as for LAB. Though LAB is much better than LUV for surface colors. LUV is mainly useful for emitters of light.

Polar Colors

Both LAB and LUV have an extended version using polar coordinates, $L^*C^*h$, which is the same $L^*$ lightness, but with $C^*$ chroma (for a given chroma, colorfulness changes as lightness changes) and $h$ hue (as an angle).

LUV, but not LAB, also has $S_{uv}$a correlate for saturation (for a given saturation, colorfulness maintains relative to lightness). Saturation is a useful correlate for data visualization, where you'd want a constant colorfulness while lightness changes.

Newer spaces such as CIECAM02, CAM16, $J_za_zb_z$, ZCAM, and others have better uniformity and accuracy than both LAB and LUV, though LAB is still very much in use.

BACK TO THE 4:2:2

So most television uses various forms of encoding to maximize useable bandwidth. The linear $Y$ luminance is encoded with a gamma curve to create $Y´$ (Y prime) also known as luma. The chroma is sampled at half the rate and encoded relative to the Y´ luma, as CbCr.

How can we get away with a lower sampling for color information? As it happens our brain's visual processing looks at chroma at about a third the resolution of luminance. Fine details are carried in luminance.

Bound or Unbound

Now clearly if a colorspace is device referred such as sRGB, it is going to be bound by the limits of that device. But a colorspace does not have to be bound, and can even have imaginary primaries that can not be created as real colors.

You can work with a linearized RGB, where there is no gamma (i.e. gamma is 1.0). We commonly work this way in Visual Effects, in a 32 bit floating point mode, instead of the gamma encoded 8 bit integer mode of sRGB. This way, while "max red" for the monitor might be 1.0, we can far exceed that with, say, red 12.0 — the value for VFX is that we can do a lot of additive image transforms, combining images in a natural way using linear math (because light in the real world is also linear).

Why $Y\ Y´$

The reason for the little trip down colorspace lane is to indicate how gamma encoded RGB spaces are probably not ideal for vector math, that is, euclidian distances won't be uniform either for light or perception.

Linearized RGB, and CIEXYZ would be a vector space, but with values relative to light in the scene or real world, and thus not uniform relative to human perception.

Colorspaces like LAB, LUV, etc. are substantially more usable as a vector space if you want distances to be relative to perception, i.e. perceptually uniform. But even so, these attempts at uniformity do not take many of the factors of human visual perception into account.

There are more complex models, such as the Hunt model, CIECAM02, CAM16, ICAM, and others that add features to predict visual perception more.

But I think an upshot here is that there is not a single, simple 3D vector space that accurately predicts human visual perception. It needs n-dimensions (depending on application), to take into account the many factors of our complex visual system, with n being a number large enough to make an all-encompassing lookup table impractical. Other relevant aspects of visual perception of light and color include stimulus size, spatial frequency, light adaptation, local adaptation, contrast adaptation, surround effects, Helmholtz Kohlrausch effects, etc.

A demonstration of this complexity is the following illusion: the yellow dots are the exact same yellow and the squares they are on are both the same grey, in terms of the absolute sRGB values. Yet they look different due to the very context sensitive, psychophysical aspects of vision

Checker Shadow Illusion with Yellow Dots

Your Second Question

As for what are the values per system - sRGB is the standard for most computers and the internet. But there are others to be sure. Several spaces share the same blue and/or red primary, while green is most likely to be different.

Here is an example (rescaled for sRGB for viewing).

colorspace compare

I hope that answers your questions, let me know if you have followups.