# Color space as a vector space

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?

• The first question is fine for this forum, the second one probably is not (but I don't know where a good place to ask would be). Although it does not quite answer your question, you may be interested in the concept of convex combinations. Commented May 9, 2016 at 6:19
• The set $\bigl\{(r,g,b)\>\bigm|\>r,\> b, \>g\in[0,1]\bigr\}$ is called unit cube. Commented May 9, 2016 at 10:56

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\ \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 euclidian difference is: $$∆E = \sqrt {\left( {L_1^*} - {L_2^*} \right)^2 + \left({a_1^*} - {a_2^*} \right)^2 + \left({b_1^*} - {b_2^*} \right)^2}$$

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.

$$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

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).

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

In practice we do the computations in a linear colorspace where there is no saturation. So, linear algebra works just fine, also with negative values for R, G, and B components. At the end of the computations you can transform back to sRGB colorspace which involves non-linear transforms and if necessary, a cut off for the maximum allowed values (e.g. a gray value of 255 for 8-bit images) and the minimum value of zero.

An example is deconvolution, I've explained here in a simple way the steps involved in transforming an image to linear colorspace, running a deconvolution algorithm and then transforming it back. Some deconvolution algorithms can lead to negative gray values, and exceeding the saturation bounds is typically always going to be an issue that has to be dealt with before transforming back to sRGB.

• This "linear colorspace" isn't really a "colorspace" but rather just $\mathbb{R}^3$ and the nonlinear transformations you mention are just examples of ways to map $\mathbb{R}^3$ to the unit-cube (where colors are uniquely defined). I do agree with this methodology, but just wanted to clarify that so we don't go saying that [-5, 900, 0.3] can be represented as a color before seeing what color it maps to, where the mapping itself is up to the needs of the user/application. Any mapping to the unit-cube will assign a color, but some are more desirable than others. Commented Feb 24, 2017 at 20:31

As it stands, the set of ordered triples [R, G, B] like you might use to represent color on a computer is not a vector space for the obvious reasons you stated: our addition and subtraction operators have this bizarre saturation effect where they can't return colors with components less than 0 or more than 1. Another way to put this is that if we did endow our unit cube of colors with ordinary addition and subtraction, we wouldn't be closed under them, since negative colors and over-saturated colors both throw errors when typed into photoshop (note photoshop error throwing is the de-facto way to check if a certain triple is a member of our color set). So the answer to your math question is no, sorry.

But maybe we can come up with a clever extension that will be a vector space? It would entail defining special operations on color components that will make them into a valid field. Since the color components are literally just real numbers from 0 to 1, I'm pretty sure this is either not possible or (more likely) I am ignorant to some cool math concept someone should mention in the comments. Perhaps if we consider only 8-bit colors who can have components with integer values from 0 to 255 we can make a finite field)?

I think an alternative approach you may not have considered, however, is to instead find a mapping from your color space (the unit cube) to $\mathbb{R}^3$, that you think is nice. What do I mean by nice? Well, I just mean that there are a ton of mappings back and forth between the sets $[0, 1]$ and $\mathbb{R}$. You'd want to pick one that "spreads the colors out" in a way you think is nice. Example: $$\tan\Big(\frac{10}{\pi}x-\frac{\pi}{2}\Big)$$

Just apply that element-wise to a color triple. Then you can just imagine the uncountably infinite set of colors in the unit cube exploding out to cover all of $\mathbb{R}^3$ and blam, one unique color for every vector. Now every vector combination can still result in a different color by using this mapping. See what you can do from there? Again, there is no formal answer to your question besides "[R, G, B] is not a vector space" so the rest is just playing around with ideas.

Speaking of color geometry, you may find this cool, but I'm sure you've already researched color space quite a bit.

• The link to that plot refuses to format correctly. Sorry! Commented Feb 24, 2017 at 19:45
• "But maybe we can come up with a clever extension that will be a vector space? It would entail defining special operations on color components that will make them into a valid field." A field is maybe a lot to ask for. But a ring is easier to achieve. Consider ([0,1], (+), .) where . is real multiplication, and a (+) b = a + b - ab. It's easy to check that this is a ring. It's not a field (because the only invertible element is 1). Thus the colourspace would not be a vector space, but a module. Close enough.
– Stef
Commented Mar 9, 2022 at 11:20