Mathematics in Color


Color is a fascinating subject. Important early contributions to our understanding of it came from physicists and mathematicians such as Newton, Young, Grassmann, Maxwell, and Helmholtz. Today, the science of color measurement and description is well established and we rely on it in our daily lives, from when we view images on a computer screen to when we order paint, wallpaper, or a car, of a specified color.

For practical purposes color space, as perceived by humans, is three-dimensional, because our retinas have three different types of cones, which have peak sensitivities at wavelengths corresponding roughly to red, green, and blue. It’s therefore possible to use linear algebra in three dimensions to analyze various aspects of color.


A good example of the use of linear algebra is to understand metamerism, which is the phenomenon whereby two objects can appear to have the same color but are actually giving off light having different spectral decompositions. This is something we are usually unaware of, but it is welcome in that color output systems (such as televisions and computer monitors) rely on it.

Mathematically, the response of the cones on the retina to light can be modeled as a matrix-vector product Af, where A is a 3-by-n matrix and f is an n-vector that contains samples of the spectral distribution of the light hitting the retina. The parameter n is a discretization parameter that is typically about 80 in practice. Metamerism corresponds to the fact that Af_1 = Af_2 is possible for different vectors f_1 and f_2. This equation is equivalent to saying that Ag = 0 for a nonzero vector g = f_1-f_2, or, in other words, that a matrix with fewer rows than columns has a nontrivial null space.

Metamerism is not always welcome. If you have ever printed your photographs on an inkjet printer you may have observed that a print that looked fine when viewed indoors under tungsten lighting can have a color cast when viewed in daylight.

LAB Space: Separating Color from Luminosity

In digital imaging the term channel refers to the grayscale image representing the values of the pixels in one of the coordinates, most often R, G, or B (for red, green, and blue) in an RGB image. It is sometimes said that an image has ten channels. The number ten is arrived at by combining coordinates from the representation of an image in three different color spaces. RGB supplies three channels, a space called LAB (pronounced “ell-A-B”) provides another three channels, and the last four channels are from CMYK (cyan, magenta, yellow, black), the color space in which all printing is done.

LAB is a rather esoteric color space that separates luminosity (or lightness, the L coordinate) from color (the A and B coordinates). In recent years photographers have realized that LAB can be very useful for image manipulations, allowing certain things to be done much more easily than in RGB. This usage is an example of a technique used all the time by mathematicians: if we can’t solve a problem in a given form then we transform it into another representation of the problem that we can solve.

As an example of the power of LAB space, consider this image of aeroplanes at Schiphol airport.

Original image.

Suppose that KLM are considering changing their livery from blue to pink. How can the image be edited to illustrate how the new livery would look? “Painting in” the new color over the old using the brush tool in image editing software would be a painstaking task (note the many windows to paint around and the darker blue in the shadow area under the tail). The next image was produced in just a few seconds.

Image converted to LAB space and A channel flipped.

How was it done? The image was converted from RGB to LAB space (which is a nonlinear transformation) and then the coordinates of the A channel were replaced by their negatives. Why did this work? The A channel represents color on a green–magenta axis (and the B channel on a blue–yellow axis). Apart from the blue fuselage, most pixels have a small A component, so reversing the sign of this component doesn’t make much difference to them. But for the blue, which has a negative A component, this flipping of the A channel adds just enough magenta to make the planes pink.

You may recall from earlier this year the infamous photo of a dress that generated a huge amount of interest on the web because some viewers perceived the dress as being blue and black while others saw it as white and gold. A recent paper What Can We Learn from a Dress with Ambiguous Colors? analyzes both the photo and the original dress using LAB coordinates. One reason for using LAB in this context is its device independence, which contrasts with RGB, for which the coordinates have no universally agreed meaning.

The Princeton Companion to Applied Mathematics

My article Color Spaces and Digital Imaging in The Princeton Companion to Applied Mathematics gives an introduction to the mathematics of color and the representation and manipulation of digital images. In particular, it emphasizes the role of linear algebra in modeling color and gives more detail on LAB space.

I have one update to the article. Since the book went to press a second edition of the book that I cite by Dan Margulis, Photoshop LAB Color: The Canyon Conundrum And Other Adventures In The Most Powerful Colorspace, has appeared ( and I do not yet have the book but it appears to have a number of improvements on the excellent first edition.

Finally, in the article I mention the problem of finding good color maps and the problems with the commonly used rainbow color map. For a nicely illustrated talk on this topic see Perceptual Color Maps in matplotlib for Oceanography given at SciPy 2015 by Kristen Thyng.

The author speaking about rainbow color maps at a UoM School of Mathematics Alumni Event at The Royal Institution, London. Photo: Chris Mann Photography.

The Princeton Companion to Applied Mathematics

For the last five and a half years I have been editing and writing The Princeton Companion to Applied Mathematics. I’m pleased to announce that the project is at the final stage, with the PDF file delivered to Princeton University Press and the book scheduled for publication in September 2015.

Over the coming months I will produce a variety of posts on this blog about the book. The book also has a Twitter feed, @ThePCAM, which will contain relevant news and links.


What does The Companion do? Briefly, it

  • introduces applied mathematics and its history, and explains what applied mathematicians do,
  • describes key concepts and equations, functions, and laws,
  • describes the main areas of current research,
  • presents a selection of mathematical modelling problems,
  • gives short examples of applied mathematics problems,
  • describes applications at the interface with other areas, and
  • covers general aspects of writing, teaching and promoting mathematics.

Here are some statistics:

Pages xvii + 994 + 16 color plates
Articles 186
Authors 165 from 23 countries
Figures 196 monochrome + 23 colour
Cross references 751
Index 2842 entries over 33 pages

The target audience for The Companion is mathematicians at undergraduate level or above, students, researchers, and professionals in other subjects who use mathematics, and mathematically interested lay readers. Some articles will also be accessible to students studying mathematics at pre-university level.

The book was edited by me and associate editors

Copy editing, typesetting, and project management were done by Sam Clark (T&T Productions, London), and the indexer was Julie Shawvan. The Princeton University Press editors were Anne Savarese and Vickie Kearn. For an interview with Vickie, see The Science of Loving Math.

The Companion already has pages on and from which it can be pre-ordered, and it is in the Fall 2015 PUP catalogue (page 62).

Here is a word cloud for the book, generated using Wordle (also available in a high resolution PDF version):