Wednesday, December 18, 2013

76 shades of gray, part 1

The book got it wrong. E. L. James missed 26 of the shades of gray. And the CIE?  You know, the International Commission on Illumination, the good folks who brought you CIELAB? They got too many shades. In 1976, they said that there are 100 shades of gray. The truth lies somewhere in the middle, almost exactly in the middle. There are 76 shades of gray.

The book that everyone has read, but none will admit to reading
The plot

I am gonna do a little gedanken here. Gedanken is the German word for "thought", which is something Germans are pretty good at. When I use this word, I refer to a "thought experiment". Thought experiments are ones that occur just inside your head. Generally, gedankens are cheaper than super-colliders and NASA probes.

Suppose I were to start with a bucket of white paint and a bucket of black paint. Let's just pretend that the white paint is absolutely the purest, brightest white that is possible. Driven snow and all that. And let's just say that the black paint is panther-drinking-double-espresso-in-a-coal-mine-at-midnight black. Remember, this is a gedanken so I am allowed to use paints made of non-obtanium.

I start by painting one little tile with the white paint, and another with the black paint. Oh, did I mention? I also have an unlimited stock of little tiles along with my impossibly white and black paint.

Next I fill a cup with the black paint and add one tiny drop of white paint. I mix this up, and use it to paint another tile. Can I tell the difference between the black tile and the one-drop-of-white black tile? Probably not. But with the infinite patience that I am only capable of in a thought experiment, I do this exercise one drop of white paint at a time until I can just barely tell the difference between the black and the slightly contaminated black. I discard all the in between tiles, so that I now have three tiles: pure white, pure black, and almost pure black.

Now, with the infinity squared patience that I am only capable of imagining in a gedanken, I continuing adding white paint, one drop at a time, saving out those tiles that are just noticeably different from the ones I already have. When I reach the stage of a tile that is so white as to be indistiguishable from the pure-as-the-driven-snow white, I stretch my back and put away my paints. After all this, how many tiles do I have? In other words, how many shades of gray are there?

A few of the gray tiles from my collection

I did this, and came up with 76 shades, including pure white and pure black. Well, I didn't actually do the physical experiment. To be perfectly honest, I got bored before I even finished the gedanken. I asked my computer to do that for me. It didn't seem to mind. Of course, I did notice that my computer didn't get me a birthday present this year. Maybe I'm just reading too much into that. I'm sure that there will be a great big package under the Christmas tree with a tag signed "With love from John's Laptop".

Details please?

Let me put a little more meat on that turkey. The CIEDE2000 [1] color difference between L*a*b* = {0, 0, 0} and (1, 0, 0) is 0.575. That means if I add just enough white to my pure black to bring the L* up to 1, then the color difference is 57.5% of a "just noticeable difference". It would follow, then, that I need a bit larger jump to make it noticeable, like almost twice as big. As a second guess, I take 1 / 0.575, which is 1.739, and that comes out pretty close. A few more interations, and I get L* = 1.734. If I believe in CIEDE2000, then this L* value is just noticeably lighter than pure black.

I can repeat this process. L* = 3.442 is just noticeably lighter than L* of 1.734. The sequence goes: 0.000, 1.734, 3.442, 5.124, 6.782, 8.814, ...

Plot of the 76 just noticeably different gray values

The plot above is getting dangerously close to something that is dangerously interesting. If we look at it correctly, it is one dimension of a uniform color space (UCS). To explain what that means, let me start by giving an example of a not-so-uniform color space: CIELAB. As I explained in my post What difference does it make, the perceptible size of a unit step in CIELAB varies depending on where you are.

Here's what we have to do to make a UCS from the plot above. In the graph above, the y axis is the L* values, going from 0 to 100. The x axis is just the count, that is, the first L* value in the list, the second L* value, the third, and so on. Let's give the x axis a name: L00, meaning an L* like thingie that is based on CIEDE2000.

What do I mean when I say it is based on CIEDE2000?  By definition, the difference between L00 of 47 and L00 of 48 is 1.0 ΔE00. By extension, the difference between L00 of 43 and L00 of 53 is 10.0 ΔE00. Once you have created the magic look up table, the complicated formula for computing CIEDE2000 is gone.

I have zoomed in on the graph above to illustrate finding L00 and computing a color difference. We can determine the L00 value of 35, by tracing along the red line from the y xis at 35, over to the curve, and then down to the x axis to get an L00 of approximately 24. Similarly the blue line tells us that an L* of 41 is about an L00 value of 29.

If I want to compute the color difference between the two L* values 35 and 42, then you take the difference between their respective L00 values: 29 in 24 is 5 ΔE00.

Computing CIEDE2000 with a nomograph

This provides a way to compute CIEDE2000 without going to the ugly formula [2]. This in itself is perhaps convenient, but not really all that exciting. The thing that is a tiny bit exciting is that this method allows us to get around the warranty for calculation of CIEDE2000. We can compute the color difference when  ΔEab is greater than 5.0.

I know that you are excited, and are fixing to send me an email to ask for a spreadsheet with this lookup table, but hold off until the second part of this post, in which I unveil a simple formula to do the L* part of the CIEDE2000 calculation.

[1] Wondering about CIEDE2000? Visit a previous post of mine.

[2] Caveat - this only takes the L* value into account. This simple method will not work when a* and b* are involved!


  1. So can one just use a uniform color space with 76 steps?

    1. It depends on what you are using it for! If you wanted to create a set of uniformly distributed gray tiles from white to black, then yes. You can probably get by with fewer, since you likely won't be able to make a few tiles at either the white-white-white end, or the black-black-black end.