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.

Wednesday, November 20, 2013

What difference does it make? (part 2)

Let's see... where did I leave off in part 1?  Our hero, Albert Munsell left us with a posthumous challenge. He developed this wonderful color space -- a way of organizing crayons [1] -- which has for some strange reason become known as the Munsell Color System. This is one of the oddest things I have ever seen in science history, by the way. One of the basic rules in the history of science is that you never name something after the person who invented it!


The wonderful Munsell Color Space had this wonderful trait that it is "perceptually linear". Well at least mostly. The thing is, there was a lot of effort put into making sure that pairs of colors that are adjacent kinda felt like they were the same distance apart as any other pair of adjacent colors.

But, the Munsell color space is not measurable, that is, I can't just put a color meter on an object and have it tell me the position of that color in Munsell units. So, they invented CIELAB -- but it did not quite have that perceptual linearity that Munsell had bragging rights to. If you took a one unit step in any direction from a given point in CIELAB space (that is, from one color), it probably wouldn't look to be the same size as a one unit step away from some other color. Also, a step in one direction (like in the direction of higher chroma) may not look to be the same size as a step in another direction (like in the direction of a slightly different hue).

So, what's a color scientists to do!?!?!

Taming of the ΔE

As I write this, I am sitting in a hotel in Hong Kong, sipping on a Coke that I bought for the alarming sum of 32 dollars (Hong Kong dollars, mind you). My wife is currently back home. For the sake of the discussion, let's say that she is in a bar in Wisconsin, listening to reggae music [2]. Also for the sake of the discussion, let's say she is also drinking a Coke, for which she paid four dollars. And let's say that my buddy Dave, who lives in Sweden, is drinking a Coke that he paid three euros for. And let's say that my buddy, Steve, in England is also drinking a Coke that he got for 2.50 pounds. While the absolute numbers are different, for each of us, the perceived cost is about the same. All of us are getting equally ripped off for drinking carbonated sugar water. 

Such it is with the adjustment that has been done to color differences. I don't mean that we are getting ripped off when we order a color difference margarita, but that there is a local exchange rate that is used to convert between actual numbers and perceived cost.

Let me 'splain a bit more about the details of that local exchange rate.

Enter CMC

CIELAB came along with a method for determining the distance between two colors. It is called ΔE. Technically I should say that it was called ΔE. Now, it's called ΔEab to distinguish it from its antecessors, which we will enumerate shorthly. ΔEab is computed in the normal Pythagorean way with all those hypotenuses and square roots and all that. It's just the distance that you would measure with a tape measure, as if the colors were all laid out in a physical model of color space. Don't let anyone tell you it's more complicated than that. A ΔEab is defined as one step in any direction, and was originally intended to refer to one "just noticeable difference".

The error in ΔEab assessment of color difference can be generally characterized by saying that higher the chroma (richer color) the larger the overestimation of a color difference. R. McDonald noticed this in 1974, and proposed a fairly simple method to correct ΔE values. I don't know this for sure, but I believe McDonald worked for J P Coates Thread Company [3]. This work all lead to ΔEJCP79.

In Old McDonald's formula, the differences in L*, a*, and b* are first converted into ΔL, ΔC, and ΔH. These represent the difference in lightness, in chroma, and in hue. I show below ΔC in green, and ΔH in red.


This is where my Hong Kong dollar analogy comes in. These three differences are then scaled, each according to the position of the colors in CIELAB space. The scaling is shown below. I didn't bother to show how to compute SL, SC, and SH, mainly because I'm lazy. 

The ΔEJCP79 Color Difference Formula

This formula was from 1979. But that gosh darn McDonald kept working on this formula. He, along with Clarke and Rigg, published a modification in 1984. This modified version was standardized in 1986 by the Colour Measurement Committee of the Society of Dyers and Colourists. They named it after their own group: ΔECMC.

The formula embodied a few general ideas that are summarized in the artist's conception shown below. First, the collection of all colors that are viewed as being "too close to tell the difference between" are described by an ellipsoid in CIELAB. Second, those ellipsoids get more elongated as you move away from a neutral gray color. Third, all the ellipses are tilted about the neutral axis, that is, they point to a* = b* = 0.

Artists conception of CMC just noticeably difference ellipses

This color difference formula has been successful. According to a recent poll by IDEAlliance, ΔECMC is currently the most commonly used color difference formula in the print industry, with 45% of the respondents saying this was the formula they used to specify color tolerances.

The menu gets longer

The CMC formula was updated in 1987 by Luo and Rigg and called the BFD color difference formula. Don't ask what me what BFD stands for, cuz I don't know. But it's probably not what you are thinking. For some reason, BFD never took off. Maybe because people thought it was not a Big Friggen Deal?


Then came ΔE94, which was accepted as a trial standard by CIE in 1994. This color difference formula is a simpler version of the CMC formula with similar performance. The CIE, by the way, is a standards organization which fits under the ISO standards umbrella. The name stands for International Commission on Illumination. For those of you who noticed that "Illumination" does not start with the letter "E", note that the committee goes under the French name Commission Internationale de l'Eclairage.

Dong-Ho Kim wrote his PhD dissertation in 1997 on yet another color difference formula. Excuse me... I meant colour difference formula, since his work was done at the University of Leeds in England. The formula was known as LCD for Leeds Colour Difference.

Like BFD, Dr. Kim's formula never got taken to the prom. Perhaps he didn't have a good publicist? Or perhaps his work was overshadowed by the work of the ISO committee TC 1-47, which published CIE 142-2001. This document introduced ΔE00 which is also known by the euphonious name "CIEDE2000".

The CIE was a bit circumspect about this formula. The document describes a recommendation, and not a standard. "A period of use, testing, and reporting by the user community will precede a determination on whether to make the new method a standard."

Now, I don't want to say the formula for ΔE00 is ugly, but let's face it. When it was born, the doctor slapped it's mother. This formula gives Stephen King nightmares. Seriously, the formula is complicated enough that I have had two different people send me spreadsheets to debug. There is an oft referenced paper that provides a data set for testing implementations of the formula.

From the standpoint of an applied mathematician, I honestly worry about all the fitted parameters. To understand why this is a concern, have a look at my blog post on when regression goes bad. Still, the standards group in the printing industry, TC 130 (which I happen to be a member of) recently ratified this as the color difference formula of choice.

Remember how ΔECMC gave us ellipses for just noticeable difference, and that the ellipses all pointed toward the neutral point? CIEDE2000 gives us quasi-ellipses which sometimes don't quite point to neutral.

Quasi ellipses, shown in a*b*, all of which have radius of 2 ΔE00

To recap, we have ΔEabΔEJCP79ΔECMC, ΔEBFDΔE94, LCD, and ΔE00. Seven color difference formulas, arranged in chronological order, with every other one catching some users along the way. (I am guessing that the next ΔE formula won't be shopping for a prom dress any time soon!) Which one is best? Generally speaking, the last formula, despite it's distinct lack of pulchritude and parsimony, agrees better with psycho-physical testing. The CIE has gone from it's original stance of "suggested formula" to "standard formula".

What about a uniform color space?

Remember my analogy about Hong Kong dollars? Wouldn't it be nice if we had once single currency that applied to colors everywhere in color space? If we could somehow warp color space so as to match human perception, life would be so much easier. Or so I think.

One problem that would go away is the so called "which color do I use to define my ellipse" problem. I glossed over this problem when I introduced ΔECMC, but consider this: with ΔECMC, the color difference between color one and color two is generally not the same as the color difference between color two and color one. In this formula, the first color is always used to "calibrate the ruler" for measuring color difference. ΔE00 solved this problem by defining an imaginary color midway between the two colors you are comparing.

Another fall of the "which color do I use to define my ellipse" problem is that ΔE00 has a warranty of 5. It is not recommended for color differences greater than that.

Really, what we want is not a way to distort ΔL*, Δa*, and Δb* values for any particular color, but rather a way to distort the whole color space so that the whole Pythagorean thing works. Apparently, I am not the only person who had that thought. Here are some folks who have entered the sweepstakes for the best uniform color space:

Labmg (Colli, Gremmo, and Moniga, 1989)
ATD (Guth, 1994)
DCI-95 (Rohner and Rich, 1995)
LLAB (Luo, Lo, and Kuo, 1995)
??? (Tremeau and Laget, 1995)
CIECAM97 (CIE standard, 1997)
RLAB (Fairchild, 1998)
IPT (Ebner and Fairchild, 1998)
L*’a*’b*’ (Thomsen, 1999)
DIN99 (DIN standard 6176, 2000)
CIECAM02 (CIE standard, 2002)
QTD (Granger, 2008)
LEaEb(Berns, 2008)
LAB2000 (Lissner and Urban, 2010)

Wow. I think this just goes to show ya. People want this uniform color space, but it's not a simple task to come up with one. One can only hope that some dashing young math guy will one day come up with a simple equation that gives us a uniform color space. Just think of the fame and fortune that this guy will receive!

---------------------------
[1] Interesting point of history here: Munsell developed a set of crayons. The rights to these crayons were purchased by Binney and Smith in 1926 to augment their Crayola line of crayons. I assume that most of my readers have heard of these.

[2] For those who are not familiar with Wisconsin, this is one of the few states where there are more bars than churches. The majority of these bars will be featuring a reggae band. I may not have this exactly correct, but someone once told me that their brother heard that Wisconsin is known as the reggae capitol of the Midwest.

[3] A thread company? Really? It may seem odd that this guy is doing color science, but consider the importance of color when looking at thread, especially when it comes to accepting a batch of thread as being the correct color. This work all lead to JCP79.

Wednesday, November 6, 2013

What difference does it make? (part 1)

I want to talk about the difference between two colors, but I need to lay some background first. This background is useful for understanding how we got ourselves into such a nice mess.

Albert Munsell, jealously guarding this cool little color toy
from two envious kids [1]

For the purposes of this blog post, I am going to say that Color Science (with capital letters) began with the work of Albert Munsell just after the turn of the last century. I call him the Father of Color Science, and I think I can get away with affixing that moniker to him because:

1. If he were alive today, he would be 155 years old, and there is still a book of his available: The Munsell Book of Color. The 2010 edition is available for the low, low cost of $994.75.

2. The Rochester Institute of Technology has a building named after him, "The Munsell Color Science Laboratory".

3. He has his own friggen' website: http://munsell.com/. At 155 years old? Complete with a blog! Although I suspect that some of his more recent blog posts were by ghost writers.

I have blogged about the Munsell color space before, in a marvelous post entitled Organizing Your Crayons. That incredible blog post gave a superficial understanding of value, hue, and chroma. That task of organizing crayons was already a pretty cool thing to be known for. But I neglected one of the really big things that he did: perceptual linearity. The colors in Munsell space are organized so as to be equally spaced according to the eye. 

The world's most attractive color space supermodel,
clearly enjoying her experience with the Munsell Color Space

This was a monumental undertaking, and the undertaker was none other than Albert Munsell. Painstakingly, he mixed colors in all combinations, at each step trying to find mixtures exactly half way between two colors. His ultimate goal was to organize colors in a way that is visually uniform. The result was the best-selling book "Atlas of the Munsell Color System", first published in 1915.

Four pages from the Color Atlas

Our messed up perception

I'm gonna ponder a bit about our perception of difference. Imagine getting a raise from $10 per hour to $10.50 per hour. Not a bad raise, right? 5%? Compare that to getting "that same raise" -- of $0.50 per hour -- if you are making $50 per hour. That's only a 1% raise. The skinflints! This example shows that our perception of salary and money is not linear. We think in terms of percentage of change. A mathematician (or an engineer who remembered her math) would say that our perception of the size of a raise is logarithmic. 

Our perception of loudness is also logarithmic, so we measure sound pressure in a nonlinear scale, decibels. Each step of ten in decibels represents a factor of ten in energy. Each step of one decibel is about a 26% increase. Our perception of musical pitch is also logarithmic, so we "measure" pitch in a logarithmic scale that we call musical notation. Each key on the piano is roughly 5.9% higher in pitch than the one just to the left of it. (Want some more math about the frequency of notes on a piano?)

The brightness of stars and the intensity of earthquakes are also measured on a logarithmic scale. The general rule that all of our perceptions are logarithmic is known as the Weber-Fechner law. The law is named after Weber and Fechner, by the way.

The same law applies more or less to our perception of color. Let's say that we give someone a pile of little tiles with different shades of gray, and ask them to find the gray tile that is half way between pure black (0% reflectance) and pure white (100% reflectance). What would the reflectance of the mid-gray be? You would think that it might be pretty close to 50%, but not so. The preferred choice is somewhere around 20%.

Nonlinearity in the chromaticity diagram

Now I'm going to take back what I said about Munsell being the father of science. Lord Kelvin (AKA James Thompson) said this about science: "When you can measure what you are speaking about, and express it in numbers, you know something about it, when you cannot express it in numbers, your knowledge is of a meager and unsatisfactory kind; it may be the beginning of knowledge, but you have scarcely in your thoughts advanced to the stage of science."

Munsell provided us with a fancy book with lots of pretty colors. He gave us a three dimensional ordering system that allowed us to uniquely specify every color in the world. I guess you could say that his three attributes are the expression in numbers of color, but I could argue either way about whether he truly provided us with a way to measure color. 

The genesis of the color measurement work came in the late 1920's and early 1930's. W. D. Wright and J. Guild (whose first names are doomed to be lost in the annals of history) performed experiments to measure the spectral response of the human eye. The culmination of that work resulted in "the standard observer" functions that were standardized in 1931. Applying this standard to spectrometer data, we arrive at the beloved X, Y, and Z tristimulus values that define the color that the human eye sees.

This was all well and good, and everyone was justifiably excited. But when the champagne had gone flat and the helium balloons lost their buoyancy, they realized that the tristimulus values were just not intuitive. The numbers did not readily relate to our intuitive understanding of hue, value, and chroma. 

The diagram below shows one early attempt at relating these numbers to something intuitive. The x axis is the x tristimulus value, and the y axis is the y tristimulus value. The brightly colored overlay shows a rough mapping of these numbers into our perception of colors.

The chromaticity diagram, showing the MacAdam ellipses

Another deficiency of the chromaticity diagram is illustrated by the "MacAdam" ellipses on the chart in the above diagram. These ellipses represent the range of tristimulus values that we would perceive as being the same color [3]. Anything within those ellipses looks the same.

Munsell provided us with a color space that had this wonderful property of perceptual linearity. Beyond just being cool, this property is of practical importance. While it is important that we can say "if two objects have the same XYZ values, then they are the same color", it is even more important to be able to specify how close to the same XYZ values that they need to be in order for us to perceive them to be the same color. And even more important still is the idea of being able to quantify when a measured color is acceptably close to a target color.

Attempts to rectify the situation

The challenge was taken up by many researchers. The goal was basically this: to find a mathematical transform to convert XYZ tristimulus values into a color space that looked like the Munsell color space. Richard Hunter, in his book The Measurement of Appearance provides a handy summary of the work that went into this effort between 1931 and 1976. I recommend printing this image off and tacking it to the wall in your office. I am sure that you will find yourself frequently referring to it.

A family tree of color spaces
(Stolen with neither malice or remorse from Hunter's book)

As you will see, the culmination of this work came in 1976, with the standardization of the color space called L*a*b*. This is a natural point for Hunter to end his color tree, since this book was published in 1975. How he came to know that L*a*b* would become a standard the year after his book was published is a mystery to me. He must have had some inside information.

L*a*b*, AKA CIELAB [4], did a good job of capturing the essence of the layout of the Munsell color space. The L* value correlates moderately well with Munsell's "value" axis. The a* and b* values can be translated quite easily into analogs of Munsell's hue and chroma. A mathematician (or an engineer who remembered her math) would be immediately reminded here of the arctangent function. 

L*a*b* also came along with a reasonably simple way to express the difference between two colors. If you lay out two colors on a three dimensional grid, you can use a tape measure to determine the distance between two colors. A mathematician (or an engineer who remembered her math) would recognize the Pythagorean theorem in this. 

The L*a*b* values are scaled so that one step in any direction corresponds to a "just noticeable difference" in color. This step is referred to as a ΔE (read as delta E). Unfortunately, a ΔE does not do a great job at predicting color difference. For example, a step of 5.0 ΔE in the direction of making yellow a more saturated color is just barely noticeable. A step of 0.5 ΔE in any direction around a neutral gray is noticeable.

As another example of the disparity between ΔE and our actual perception of color difference, one brilliant researcher devoted an entire blog post to counting the number of discernible colors. An entire blog post! Can you imagine that?!?!? When counted in L*a*b* space, there were something over 2 million. But the real number is somewhere closer to only 346 thousand.

What was needed is a more accurate way of expressing color difference. That's the topic of the next part in this series.

-----------------------------------------
[1] I need to be fair here. Albert Munsell was a brilliant man who devoted his life to understanding color, and to teaching kids about color. 

[2] At least that's the way they look on my monitor. Like most computer monitors, mine is not calibrated, so I can't really be sure what the ramps will look like on your monitor!

[3] Technically, the ellipses are drawn at ten times that threshold of just noticeable difference.

[4] These are the only correct names for this color space. They are routinely called Lab or CIELab or even LAB. These are all incorrect and naughty. Note that Hunter invented Lab, so it is just plain wrong to call CIELAB by this name. Wrong. 



Wednesday, October 30, 2013

Tolerances for spot colors

There is a little bit of a hole in the most recent version of the ISO spec for flexo printing[1]. I will explain the hole, discuss my analysis, and provide a patch for this hole, but first a bit of background.

There is a family of standards called ISO 12647, which all cover printing. In particular, they provide some target color values, along with acceptance tolerances around those colors. In almost all case, those tolerances are in terms of ΔE, with the newer revisions of the standards shifting from ΔEab to ΔE00.

Part 6 of this standard is devoted to standards for flexographic printing. Flexo printing is used on such a wide variety of substrates that it is often not possible to nail a particular color. As a result, tolerances based on a ΔE-type color difference are not possible. One has to be content with getting the correct hue.

ISO 12747-6:2012 states target hue angles for C, M, and Y, and provides a ±6o tolerance. Spot colors are also given a tolerance in terms of hue angle, but it’s ±8o. Black, however, does not have a hue angle tolerance. This makes a great deal of sense, since black is neutral. The hue angle is undefined.


Tolerances from ISO 12647-6

But, “black” is not the only black. My Pantone book lists six shades of black. Presumably, the target a* and b* values for these inks are also 0, so the hue angle is undefined. This is the question that led to the realization of the hole in the standard: “how can analysis software decide if the ink name ‘midnight’ or ‘inkwell’ is equivalent to black?”[2]

Worse yet, what if the target for a spot color is not quite exactly neutral, but near neutral? If the chroma[3] of a spot color is small, then a tolerance of 8o might be impossibly tight. For example, in my Pantone book, the ink “Warm gray 5” has an L*a*b* value of {69.61, 2.58, 1.00}. Let’s say the hue of this ink is rotated by 8° to {69.61, 2.70, 1.63} so as to be at the very edge of acceptance in terms of hue. The color difference is a meager 0.38 ΔE00. Holding a printer to a 8° tolerance is pretty tight.

For highly saturated colors, a tolerance of a specified number of degrees around a target hue is perfectly reasonable. But as a color gets closer to a near neutral, it would be preferable to shift over to a ΔE00 tolerance. At what chroma value do you need to shift between a ΔE00 tolerance to a hue angle tolerance?

First naïve approach

I call this the naïve approach, because I am going to make a mistake. It turns out that the mistake is not huge, and it gives some intuitive understanding, so I will leave it in on this first pass. Watch for the mistake.

The figure below shows two colors r1 and r2, in the a*b* plane. Both have a chroma of c, but are separated by 8o. If r1 is the target hue, then r2 is at the edge of the 12647-6 tolerance window.

The arc length between the two colors is fairly trivial to compute. I could use the normal trig stuff, but since the arc is so small, I will just estimate the ΔE (which I a straight-line distance) with the arc length.


Thus, if we assume a tolerance of 1.5 ΔE, the crossover is close to a chroma of 10. Below that point, a hue tolerance is overly restrictive.

Second, not so naïve approach

Did anyone catch the mistake I made? Yes, you in the back? Ahhhh… the old accidentally used ΔEab instead of ΔE00 mistake! The formula for ΔE00 is just a tiny bit more complicated than the formula for ΔEab.[4]  So, I need a slightly less naïve way to look at this problem.

Suppose I picked a color at random, and then rotated it by 8° - that is to say, shifted the hue by 8° without changing L* or the chroma, C*ab. What is the color difference (in ΔE00) between the original color and the hue-shifted color? Then let’s say you computed that for a whole big bunch of colors just to see how it all played out. You would expect that, the larger the chroma, the larger the color difference, right?
Well, I just happened to have a large collection of colors (11,488 of them to be exact) just laying around from a blog of mine on counting colors. Below is a plot of the color difference caused by an 8° hue shift as a function of chroma.
Color difference caused by an 8° hue shift
Is this cool?

To answer the rhetorical question, yes, it is cool. But the data is a bit sparse down there in the lower left-hand corner around 1.5 ΔE00 where we are looking for our answer. This is not a surprise, since my color database only includes colors on a grid with spacing of 5.

So, I took a little different approach. For my next plot, I looked at points in color space with a chroma of 10. (This is the estimate we came up with by analyzing ΔEab.) These are all shades of gray, essentially, with a moderate amount of a color cast to them. I looked at how much color difference there was for each of them when they shifted in hue by 8°. The plot below shows this color change as a function of original hue angle.

The color difference caused by an 8° change in hue, as a function of hue angle

We see that the amount of color change oscillates between 1 and 2 ΔE00, so the average must be somewhere around 1.5 ΔE00. The true average is 1.45 ΔE00. Going back to Table 4 from ISO 12647-6, this is really close to the variation tolerance for spot colors.

For an ink with a target chroma of 10, a tolerance of 8° is roughly equivalent to a tolerance of 1.5 ΔE00.[5] Based on that, I have a simple recommendation for spot colors: If the target chroma is less than 10, then the appropriate tolerance is 1.5 ΔE00. For target chroma of 10 or greater, then the hue angle tolerance of 8° should be used.

Just in case someone wants to repeat this analysis for angles other than 8° or color differences other than 1.5 ΔE00, I provide the useful nomograph below. The t-shirt version should be out just in time for Christmas.

Nomograph for determining the crossover chroma
for various combinations of color difference tolerance and hue tolerance

The red line on the nomograph shows the determination of the crossover chroma between tolerances of 1.5 ΔE00 and 8° of hue. The graph shows a crossover at C* = 10.5. Just between friends, let’s call it 10.



[1] I am not blaming any of the diligent folks on TC 130 who reviewed this document. I was one of them!
[2] Thanks to Bruce Bachmann and Mike Sisco for this realization.
[3] I am using the word “chroma” to mean C*ab, which is defined as 

[4] Well, to be fair, the formula for ΔE00 is just a tiny bit more complicated than the formula to get a balanced budget.
[5] One caveat: I have made the assumption that the only change in color is in hue angle.

Wednesday, October 23, 2013

Color Picker Pen

(An update to this blog post can be found at "Scribble Pen".)

As John the Math Guy, people are always asking me stuff. Often the questions are like "When are you gonna get off that darn computer and fix that leaky faucet?" Or "Why are you so ugly?" These, of course, aren't really question at all, but every once in a while I get a real question. Today, the question was "how does this gizmo work?"

The gizmo in question is called the Color Picker Pen, designed by Jinsu Park. Lemme tell you, it's pretty cool.

You start by holding one end of the pen up to an object and clicking the color scan button. A color sensor measures the color of that object. In the picture below, the pen has picked up the green of the leaf, and note that the color display (along the side of the pen) has changed to indicate green.

Grab a color

So far, this is a cute little gadget. But now the real fun begins. This is a pen, right? The really cool thing is that you can now use the pen to write with whatever color you just scanned. Kind of like the Photoshop eyedropper tool, only it works in the real world rather than in the cyber world within Photoshop. (You know, where all models are a size zero, and don't have pimples or cellulite?)

Draw with that color

Wow!

But I was asked to explain how it works. The answer is simple. It doesn't. Don't get me wrong. It's a great concept, a cool idea, but, at least as shown in the diagrams, it seriously won't work. And, it was never advertised as a real product. Actually, you can find a lot of websites by googling "color picker pen", and many of them refer to this as a "concept", an idea that has not been turned into a real product. 

Internal organs of the Color Picker Pen


The sensor

The sensor for this pen is plausible. There is a color sensor available from MAZeT that would fit the bill. This is a true XYZ sensor, which means that it is a bit better than an RGB sensor in terms of color fidelity. (An RGB sensor will see some colors distorted.)  The sensor itself is shown above... certainly small enough for the color picker pen. Below the sensor is a prototype board. At the right side of the board, you will see a USB connector, so that gives you an idea of the size of the board. If you remove the USB related components on the board - which would not  be needed - you might be able to fit the board into the end of a fat pen.

MAZeT sensor and prototyping board

Of course, a few things might be missing. If I were designing this, I would likely try to add a white LED because I wouldn't trust ambient light, which can vary in intensity by many orders of magnitude. And especially since the user would generally want to push this thing right up against the leaf, effectively shielding the leaf from any ambient light. But this LED might make the whole thing too large, since it would be necessary to shield the sensor from the LED.

There is still one thing that is bothering me about the sensor, though. Below I show a closeup of the sensor end of the pen. Anything funny about it? Think now. What color is the end? It's a dark gray?!?!?  Why would an optical designer put sunglasses over a color sensor? It's pretty dark. Just taking a wild guess, I would say that it reduces the light to the sensor by a factor of 10. Not a good thing.

Close up of the sensor end of the Color Picker Pen

So far, it sounds like this could perhaps be built, but that it is unlikely that the pictures represent a real design.

The display

The Color Picker Pen offers a nice feedback feature: the pen will light up to tell you what color ink is measured / loaded. Is this feasible?  I borrowed a pen that belongs to my wife to show that, yes, such an animal exists. Those of you who know my wife, I would appreciate if you didn't mention that I borrowed her pen. I told her I was going to be fixing that leaky faucet.

Pen for writing love letters in the dark

This pen has a battery and a blue LED. Clicking the switch on the top will turn the light on or off. This could easily be done with a tricolor LED so that a wide range of colors can be produced along the side of the pen.

The battery in my wife's pen reminded me of something else that is needed. In my palpable excitement over this pen, I forgot all about the need for a battery! I didn't see a place for one, or a way to replace it, but let's just say that could be done. Since there is no evident way to replace a battery, it is sounding more like this is a concept design, and not a real product or prototype.

The other electronics

Of course, maybe there needs to be a microprocessor as well? Ok... I guess we can make some space for that. Maybe it would fit? I dunno.

The inks

Now we come to the fun part. The ink. Once again, I have taken a close up of the internal organs shot. Quite clearly, it shows a red, a green, and a blue ink cartridge. That's where the color scientist in me immediately says "nope, not a real product".

Close up of the ink

Why do I say that? Well.... Lemme ask you a question. What color inks are used in your home printer? Red, green, and blue? Nope. Sorry. They are cyan, magenta, and yellow. Below you see the four printing inks from my home printer. Cyan, magenta, yellow, and black. No red, no green, and no blue.

The inks for my printer

Perhaps I just have a cheap printer, you say? Well, that's true, but let's consider the other end of the spectrum. I put my latest Boston Proper sales flyer on my scanner, and collected this image. Note, especially in the white of her alluring eye, that there are no red, green, or blue dots. The dots are cyan, magenta, and yellow. The printing press that this was printed on cost a little more than my home printer - I dunno the exact figure, but I am putting it around $10 million. They don't use RGB inks. 


The choice of CMY (with the addition of black) over RGB is a fascinating story. I will get around to telling it sometime soon. For the time being, let me say this. If you mix red and green ink, you get a dark and dirty brown, almost black. If you mix red and blue ink, you get a very dark blue, almost black. If you mix green and blue, you get another really dark color. So, mixing RGB inks, you can make red, green, blue, and three lovely shades of black.

Let's change up the inks. If you mix cyan, magenta, and yellow, on the other hand, you can get a whole bunch more colors. Cyan and magenta ink mix to make a purplish blue. Cyan and yellow make green. Magenta and yellow make an orangeish red. If you mix all three inks, you get a dark brown, almost black.

So, my assessment of the Color Picker Pen is that no one ever built one. If they had, they would have realized that red, green, and blue don't make for a very wide collection of colors. They would have then called John the Math guy to help them figure it out and I would have recommended cyan, magenta, and yellow. Since I never received such a call, I have to assume that the Color Picker Pen was never built.

So, why are color cameras RGB? And why is a computer display and a TV RGB? Questions, questions! I will leave them for another blog!