Formal algebraic notation for RGB color scale?

659 Views Asked by At

BACKGROUND

I'm trying to write down an algebraically rigorous (read: pedantic) expression for colors in the RGB "space". All I know is that I have a set \begin{equation} \mathcal{S} = \{R, G, B\} \label{eq:set} \end{equation} of three qualitative "entities" (for lack of a better term), each of which can take on a value in the set \begin{equation} \mathcal{K} = [0, \cdots, 255] \end{equation} of possible coefficients. Note that I'm not making any assumptions as to the orthogonality of the elements of $\mathcal{S}$.

QUESTION

How can I write down the vector space $\mathcal{C}$ in which colors "live" in both a rigorous and compact way? I initially thought of writing \begin{equation} \mathcal{C} = \mbox{span}\{\mathcal{S}\}, \end{equation} but that doesn't look right since $\mathcal{S}$ is a set of "labels" more than a set of vectors per se. Do I then have to go as far as writing down \begin{equation} \mathcal{C} = \mbox{span}\{ \mathcal{V} \} = \left\{\sum\limits_{c} \lambda_{c} v_{c} \mid c \in \mathcal{S}, \lambda_{c} \in \mathcal{K}, v_{c} \in \mathcal{V} \right\}, \end{equation} where \begin{equation} \mathcal{V} = \left\{ [1,0,0], [0,1,0], [0,0,1] \right\} ? \end{equation}

The problem is that this latest expression for $\mathcal{V}$

  1. looks clumsy,
  2. doesn't scale to large dimensions since it's a brute-force enumeration, and
  3. does not say which dimension corresponds to which color since $\mathcal{S}$ is by default an unordered set---so we're left with yet another aspect of the problem to transcribe.

EDIT

Calling $\mathcal{C}$ a vector space has raised quite a few eyebrows. I shall therefore refer to it as a bounded, discretized, "space of vectors". Please let me know if you have a better term for it. The fact remains that vectors for colors live in that "space".

3

There are 3 best solutions below

0
On

To add to ThorWittich's answer, if you REALLY want to work with the finite field of order 256 and not a set of 256 elements, I'll show you how to define this in an "easy" to understand way.

Any element in your field $\Bbb F_{256}$ will be a polynomial $f = a_0 + a_1x + \cdots + a_7x^7$ with coefficients that are either $0$ or $1$. Next we need a reduction polynomial, which is a polynomial of degree $8$ with coefficients as above that is irreducible in $\Bbb F_2[x]$. What this means exactly is not important. We can take $$ r(x) = 1 + x + x^3 + x^4 + x^8. $$

Now addition in your field is defined by adding coefficients in polynomials and reducing them modulo 2. Multiplication is defined by multiplying two polynomials as you are used to, with a twist. If the polynomial you get from multiplication is of degree higher than $7$ then you divide it by the reduction polynomial $r(x)$. The remainder from this division with coefficients modulo $2$ is the result of your multiplication.

What this should tell you is that this is probably not what you want to do.

0
On

One immediate problem is that we don't even have a good compact notation for the set $\{0,1,2,\ldots,255\}$ in the first place (unless you've had too much axiomatic set theory the night before and claim that this set equals the number $256$ ... but that won't fly with a general readership).

It is fairly common in the context of color spaces to view $\{0,1,2,\ldots,255\}$ simply as an (imperfect) representation of the unit interval $[0,1]$, implicitly letting $n$ stand for $\frac{n}{255}$.

If this idealization works for you, you can describe the color space as simply $$ [0,1]^3 $$ and leave it to convention which of the three channels denote red, green, and blue, respectively.

It won't give you a vector space, but that is to be expected, because the space fo 24-bit RGB colors doesn't actually support arbitrary sums and differences of colors, like a vector space ought to. It can be seen as a subset of the vector space $\mathbb R^3$, though -- so you have some justification for using vector space operations inside formulas as long as you remember to explain what happens if the final result falls outside the gamut.

(In particular $[0,1]^3$ is a convex subset of $\mathbb R^3$, so you never risk falling outside it by interpolating or averaging between already known colors).

1
On

A natural(?) way is to view a colour as a measure over the (visible) range of wave lengths (or frequencies), so that $\int_a^b\mathrm d\mu$ answers the question: How much energy is transmitted in the wavelength range from $a$ to $b$ per time unit? The characteristics of receptors in the human eye, or the characteristics of the construction of RGB displays reduce this to a measure on a finite space. In other words, you consider the set of functions $\{R,G,B\}\to [0,\infty)$ (perhaps even including $\infty$). These measures do not form a vector space, but you can add or scale or convex combine them, etc.

Additional constraints on real world monitors (and image file formats) impose an upper bound on the power per channel as well as quantization effects (but not linearly - see $\gamma$ correction!), but it depends whether you want to adhere to these before a final step in your processing.