Wednesday, September 19, 2012

How many colors are in your rainbow?

“Ok, mister smarty-pants Math Guy who thinks he’s a color scientist, answer me this!  Just how many colors are there? Huh?”  I get that question all the time. Boy have I got an answer for you. Or maybe a whole bunch bunch of answers…
This blog is dedicated to Jerry Nelson, the voice of The Count from Sesame Street. Jerry died August 23, 2012.
The Count
The simplest answer is that there are three colors: red, green, and blue.
On the off chance that you don’t believe me (maybe you were gonna say there are more?) pull out a magnifying glass, or a microscope, and look at your computer monitor. Unless you happened to grab a scanning electron microscope[1], you probably see something like the image below. Your computer screen is a combination of red, green, and blue dots. Every color that you can see on your screen is a combination of those three colors. 
Picture of red, green, and blue pixels on a computer screen
For the sake of honesty, I have to say that this last part was something of a lie. Not really a lie, but perhaps misleading – like telling your wife that you are out with “the guys”. The thing is, you can’t get every possible color on your computer monitor. You can get a whole bunch of them, but have a look at the chromaticity diagram[2] below.
The chromaticity diagram, showing the gamut of a hypothetical computer monitor
The black triangle shows a hypothetical gamut for a computer monitor. The three vertices of the triangle represent the colors of the red, green, and blue pixels. By mixing the colors, you can reach any color within the triangle.
You will note that there are colors that are outside the gamut of this hypothetical monitor. In fact, it is impossible to build a computer monitor with three fixed lights that will display all possible colors. Chromaticity space is bowed out, so you can’t make a triangle with physically realizable colors (colors within the horseshoe shape) that covers all possible colors[3].
Here’s another fun experiment. Go into Photoshop or Paint or whatever program that allows you to select colors. Try to make orange. Not only can’t you find a word to rhyme with orange, but you can’t make a good orange on a computer monitor[4]. The best I could do looks a little brownish.
The best orange I can make on my monitor (RGB = 255, 192, 0)
So, my first answer to the question is that you can make good percentage of all possible colors out of just three colors. Four colors might be a bit better.
How about the number of colors in the rainbow? The colors from the rainbow can be combined to make every possible color. Isaac Newton did some research with prisms and sunlight, and decided there were seven colors in the rainbow: red, orange, yellow, green, blue, indigo, and violet (ROYGBIV). The other colors I get, but what about indigo? I’m not sure I even know what indigo is!
Here is my explanation of how indigo got into the rainbow. Newton saw a big section in the blue that seemed just too wide to be a single color. Now, Newton was something of a mystic, so he saw a fundamental connection between the seven elements, the seven planets, the seven notes of the tone scale on the piano, and the seven colors of the rainbow.
Or maybe he looked at the color just below 500 nanometers, and rather than call it light blue or cyan, he decide that was blue. Having no other name, he was forced to use indigo to name the color that I might call blue or possibly dark blue. This is at least plausible, since the word “cyan” didn’t come into use in the English language until 1879.
My second answer to the question of how many colors there are is seven, or maybe six.
Sixteen million
Now I’m going to go to the other extreme, and claim that there are 16,777,216 colors, and that my computer monitor can prove it. Those of you who recognize this number as 256 X 256 X 256, will immediately understand that this is the number of RGB combinations you get when you have 256 levels of red, and 256 levels of green, and 256 levels of blue. If you do not recognize this number I’m sorry, but you are a poor excuse for a computer geek.
Just because I can go into Photoshop and make 16 millions colors, does that mean there are really that many colors? The image below might persuade you that there are (possibly) not that many. One of the rectangles has the RGB values 255, 255, 255. The other has the RGB values 254, 254, 254. I don’t know what you see on your screen, but I can’t really tell the difference.
In other words, while there are 16 million possible combinations of RGB, not all of them are distinct “colors” according to the eye.
Which rectangle is brighter?
My third answer is that there are 16 million colors on my computer display, but that might be a little bit of computer hype.
I taught an algebra class at UW Milwaukee. One day I gave a pop quiz to my two classes. I asked them to take out a sheet of paper and a writing implement. I gave them two minutes and asked them to write down all the single-word color names that they could think of.
The eleven colors that everyone can think of
I had 50 students that took the quiz, half male and half female. Almost everyone – 48 of the students – came up with the names of the eleven colors in the picture above: white, black, gray, red, orange, yellow, blue, pink, brown, and purple. If I remember correctly, there were two students who said that their art teacher told them that black is not a color; it is the absence of light. So that explains that. What do art teachers know?
The next two colors down the list were silver and gold, each with about half of the students recalling those colors. I am going to argue with the art teacher that silver and gold are not true colors. They are gonio-apparent effects. And I am right, since this is my blog.
So, my fourth answer is that there are eleven basic colors that everyone can recall.
An interesting thing showed up in the data. There was a statistically significant difference between the number of colors that the men could recall versus the number that the women could recall. Men averaged 15, and women averaged 18. Not a big difference, but my sample was wide enough that it was significant. Now, it could be that my sample was not representative of the population since there is a bit of a gender difference in math performance and this was an introductory algebra class taught in a college. OR it could be that women are inherently more color conscious. I have no real explanation, other than stating what I observed.
The student with the most colors was a female art student, who recalled 29 colors in the two minutes allotted. I have given this test to a number of other times, in particular, to my wife. In two minutes, she was able to recall over 50 single word color names. After the two minutes were up, she kept writing down single word color names for a few hours after, eventually compiling a list of nearly 250. Can there be any question about why I fell in love with this woman?
Answer number five: there are somewhere around 250 colors that my wife can name.
Something like fifteen
I performed another experiment, this time on myself. Unlike many of my other experiments, this one did not involve mind-altering chemicals. It involved colors. I started with a big bucket of possible colors, and tried to assign each of these to a color family. I started with the eleven basic colors as my names for color families.
There were a lot of colors that fit in more than one family. For example, yellowish orange belongs in both the yellow and the orange families. And reddish green fits into both red and green[5].
As I went through my bucket of colors, I came up with a few sets of colors where I wasn’t comfortable with putting the color in any of the families. One group could be called beige, taupe, off-white, or possibly eggshell. These were colors that were really not white, but they were not saturated or dark enough to be called brown or yellow. Another misfit color was tan. Is it brown, or yellow? Not really either, I think. Or maybe it’s really brown.
Another group that didn’t seem to have a proper color family included the colors coral and fuchsia. Were these red, or orange, or maybe pink? I couldn’t decide. Maybe it is in the purple family? Nothing seemed to fit
And then there was plum or burgundy, kind of a brownish dark purple. Maybe sea foam was another group, and that group might include the color that my wife argues with me about. Cyan, turquoise, aqua, powder blue, sky blue, teal, periwinkle, azure, cerulean… (Are you kidding?!?!??  Periwinkle doesn’t belong with those colors!)
I count three or four or maybe five additional color families, so my sixth answer is that the total number of color families is around fifteen. But, I have no idea what a different observer might say. I hesitate to run this experiment on my wife.
One hundred fifty or two thousand
It wasn’t that long ago that the biggest box of Crayola crayons available (with 96 crayons) was proudly displayed on my desk. Today, I see that you can buy a set of 150 crayons for the low price of $14.97. A must have for any serious color scientist. My birthday is coming up, by the way.
Crayola 150-Count Telescoping Crayon Tower
Crayola is not the only company that is compelled to add more colors. Pantone just recently announced the addition of 336 colors to their color formula guides, bringing them up to “1,677 chromatically arranged color choices to unleash their passion and let their creativity soar.” I heard many passions unleashed by printers at the necessity to drop another $100 on their color matching books.
Not to be outdone, the Valspar American Tradition paint swatch book has 1,764 colors, including “Homestead Resort Parlour Raspberry”, “Misty Morning Blue”, and the very popular “Swampwater”. Swampwaters were very popular when I was in college. No one knew what went into them.
So, the number of commercially distinguishable colors is somewhere between 150 and 2,000. My seventh answer to the question.
Two million
Now we get to some more scientific answers. Let me make the question a bit more precise. How many distinct colors can be reliably distinguished by people with normal color vision?
The quick and dirty answer comes from looking at the bounds of CIELAB space[6]. CIELAB space was designed so that one step in any direction is approximately “just noticeable”. The value of the lightness value goes from 0 to 100. In the red to green direction there are let’s see, how many steps? Lemme check my copy of Wysczecki and Stiles. Hang on a sec… Still looking…
Ok, so they don’t say how big color space is in that direction. Or in the blue to yellow direction. Let’s just assume that there are something like 200 steps in each direction. That means that the rectangle that fits all of color space is 100 X 200 X 200, or about four million.
Of course, this assumes that color space is a box-shape (rectangular prism). But color space is not rectangular. Maybe it’s more like an ellipsoid? My buddy Adam has referred to the shape as a “space potato”. Let’s just say that it’s an ellipsoid, in which case, the volume is about half of the volume of the box, or two million. Answer number eight.
Some other number?
How many lies have I told so far? Well, I need to admit to another one, or at least another misleading statement. (Honest, I was out with the guys that night.) I said that “CIELAB space was designed so that one step in any direction is approximately just noticeable.” I did put the word “designed” in italics to tip off that this might be a white lie.
I have to admit that, yes, this was the design goal, but it is not really all that exact. For example, if you take five steps in the direction from saturated yellow to really saturated yellow, you will just barely be able to tell the difference in color. On the other hand, if you have a color near gray, you can get away with only about half a step before you can see a difference.
This means that the reconnoitering in that last section is a bit flawed. What’s the real number? I honestly don’t know. I have some ideas on how to compute it, though. I do know that there are only about 70 steps in the lightness direction, whereas CIELAB says there are 100.
My ninth and final answer: Someday I will actually write some code to figger it out, but I suspect the number of discernible colors is around 689,262. Then again, maybe it’s the Count’s favorite number: 34,969.
So, how many colors are there? I dunno. It depends on how you ask the question and who you ask. Pick a number between 3 and 16,777,216.

[1] SEM images are still back in the days of black and white. If you see an SEM image with any other colors in it, it has been colorized. Someday, someone will figger out how to make electrons with different colors, and then the images will be really, really cool. I think I’ll go file for a patent on that idea.
[2] The chromaticity diagram was an early attempt at trying to turn the spectral response of the eye into something that explained our perception of color. It was replaced by other mathematical models (in particular, CIELAB), but is still the easiest way to understand the gamut of a set of light sources.
[3] Sharp introduced the Aquos Quattron display in September of 2010 which added a fourth color of pixel, yellow. For this monitor, the gamut is expanded into a quadrilateral that gives you more yellow and orange colors.
[4] Speaking of orange… I think that carrots are a richer orange than oranges are. I think we should swap the names of these too foods.
[5] Ok, I was just kidding about that one. Reddish green isn’t a color; it’s the name of the band I am going to form after I retire from all this color stuff and learn to play the sax.
[6] CIELAB was the next big step forward in coming up with a measurable number that corresponds intuitively to our perception of color. For dinner, a movie, and plane tickets, I will come to your living room and give the CIELAB lecture to you and ten of your most intimate friends.


  1. we need look no further than Joseph and the amazing technicolor dreamcoat.
    the answer is clearly 29 (or maybe 27, or 26 if you're an art teacher).
    red and yellow and green and brown and
    Scarlet and black and ochre and peach
    And ruby and olive and violet and fawn
    And lilac and gold and chocolate and mauve
    And cream and crimson and silver and rose
    And azure and lemon and russet and grey
    And purple and white and pink and orange
    And blue
    Newton, phah...Tim Rice and Andrew Lloyd Webber have the answers (except for silver and gold.....oh yeah, and black)

  2. Great musical, Steve! That totally slipped my mind. :)

  3. John, what I forgot to say was thank you for a fantastic article

  4. Great article John. I thought the CIELAB point was especially interesting. If there are roughly 2 million "just noticeable" steps in CIELAB would that mean that the current standard bit depth of 8-bits/channel is sufficient for even the largest color gamuts? I've heard a lot of concern about banding with 8-bits and wide gamut but it strikes me that 16+ million colors might be enough headroom except in the most extreme, not found in nature, cases.

  5. Thanks, Jeff, for seeing a very practical consideration of this somewhat fanciful discussion.

    Are 8 bits enough? It would seem that maybe they are, except that they might not be distributed appropriately. The eye is nonlinear. At the high end (near 255) we might not notice a change of even a few gray levels. At the dark end, our eye is more sensitive, and one gray level might be huge.

    But, on the other hand, cameras are historically not linear beasts. They have a gamma associated with them, which boosts the midrange. Industrial cameras used to have an analog circuit to do this gamma. Today they generally have 10 bits or so feeding into a look up table to make this gamma. There is usually a switch to turn this off.

    As a result, there is compression in camera images at the high end, and stretching at the low end. This means that the camera sees something more similar to what our eye sees, so 8 bits isn't so bad.

    But on the third hand, images don't all come from cameras, and are often displayed on a monitor. The whole gamma thing came up back when we were using CRT displays, which are very nonlinear. We needed to boost the midrange to make images look correct. Rather than fix the monitor (maybe by adding a profile) camera manufacturers jumped on a solution.

    Today, monitors are closer to linear, so... I dunno what this means! I'm confused. Is there a lookup/profile between the monitor I am looking at right now, and the image that is displayed via Windows?

    I guess... if an image has a gamma associated with it and it is understood that the gamma has been applied, and what the gamma is, then 8 bits might be just enough.

  6. You may recall prior to softproofing, drum scanner operators could only trust the screen tint Atlas books. These were printed with the printers own press, paper and inks. The step increment bewteen blocks or patches was 5%. So, from 0-100% there wer 20 steps for each color. 20C x 20M x 20Y = 8,000 colors. Adding K for another x20 (160,000) was redundant and not needed.

    Steve Suffoletto