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!

Wednesday, December 4, 2013

Visual accuity and color

As the only John the Math Guy around, you can imagine that I get a lot of questions.  I do. Thousands of questions a month. Normally they start out with "when are you gonna..." and end with "pick up your dirty socks?" or "get home from the bar?" or "fix the door knob?" But every so often, I get a question that isn't a thinly veiled command. Here is an example.

"How does visual perception of sharpness (acutance, resolution, and contrast all considered) vary with color?"

    - if fine marks need to be visually evaluated and black is not an option, what other color is the next best choice?
    - where has an MTF at one frequency vs wavelength plot been published?

    My usual references; Wyzecki and Stiles, Hunt, Zakia and Todd, etc.
    don't seem to address this particular issue. A new edition by
    Lambrecht and Woodhouse gets tantalizing close, but their emphasis is
    primarily black and white photography.

    Any suggestions?
Larry

Wow! An intelligent and interesting question! And I think I can provide a decent answer!

I am sure you have noticed that when you look at yellow halftones with the naked eye, you really can't see the dots, even when you can see the color. This fact leads to your question, since it implies that visual acuity somehow depends on wavelength.

The sensors in the eye are either rods or cones. The rods are largely active when old guys like me get up in the middle of the night to go to the bathroom. In normal daylight, these are pretty much saturated, so they don't have much effect on vision.

The cones are the sensors in the eye that are most important under daylight. If I were haughty, I would say something like "under photopic rather than scotopic conditions." And I would likely slip those words into casual conversation whenever possible. Much like ice cream cones, the cones in the eye come in several flavors. Not quite as many as Baskin Robbins, though. There are only three flavors of sensors in our eyes: cherry, mint, and blueberry.


Unretouched photomicrograph of Burt Baskins' retina

Some sadly mistaken people call the sensors in our eyes "red, green, and blue". Real color scientists who don't like ice cream call them L, M, and S for long, medium, and short wavelength. Red, green, and blue are not quite appropriate since the cones don't exactly line up with what we would think of as red, green, and blue. The L cone (the reddish one) overlaps quite a bit with the M cone (the greenish one).

The spectral response of the S, M, and L cones

Here comes the important part. There are more of certain types of cones per square millimeter than there are of others. In the fovea (that's the very central part of the retina in the center of our field of view), only about 5% of the cones are S cones. So... these cones are less tightly packed than others. So... our resolution (visual acuity) is less with the S cones. 

Look at the spectra of yellow ink. 

The reflectance of yellow ink is down at 5% to 10% in the 400 nm to 500 nm range, and close to the reflectance of paper above 500 nm. The S cones are the only cones that are sensitive in this range, so our ability to see yellow halftone dots is because of the sparsity of S cones in the fovea. And that, my friends, is why you can't see yellow halftone dots without a magnifier.

By the way... there is this company called Beta Industries that sells this really cool microscope that illuminates a sample with blue light so that you can look at yellow ink with just your S cones. You can illuminate with red light to see cyan, and green light to see magenta as well. But the really fun one is yellow ink and blue light.

Let's get back to the original question. Clearly yellow would be the worst possible choice for making dots on the paper that are just barely visible. Clearly, black is the best ink. Of the other two, which is preferred?

Generally speaking, there are twice as many M cones as there are L cones, but this varies from individual to individual. This means that, in general, the eye has better visual acuity in the green region of the spectrum, and somewhat less visual acuity in the red.

Let's say we are considering what is going on in the green region of the spectrum, from 500 nm to roughly 600 nm. Which ink shows the most contrast against white?  In other words, which ink has the lowest reflectance in this region? If we are limited to the four basic inks, both black and magenta have low reflectance in this region. So, if we want a single ink, then magenta would be the second choice if black is unavailable.

Cyan ink shows a bit of contrast against white in the green region (look at cyan ink under green illumination to see this), but has a fairly decent contrast in the red region. Thus, one would expect that cyan would have decent visual acuity, but not quite so much as the magenta.

But, as I said: 1) there is a wide overlap between the spectral range of the L and M cones, so we can't really think of there being a sharp distinction between L and M in terms of wavelength, and 2) there is quite a bit of variability in the relative number of L and M cones in different people, so one rule may not apply to all people.

If you are allowed a bit larger range of inks, then blue ink would be best, since it has good contrast both in the green and red regions of the spectrum. But if blue is being made by overprinting cyan and magenta inks, then register could cause problems.

One more consideration is the strength of the ink. Obviously, if you print at a higher density, you have better contrast. This would tend to favor black ink over cyan and magenta (which are typically printed at comparable densities), and both would be favored over yellow.

So, all in all, I would go with magenta ink, if all you have available is CMYK. If you have a spot color available, I would go for a dark blue. You can quickly check the contrast by viewing the ink under green illumination.