Wednesday, September 25, 2013

A YouTube tour through Brazil

As they say in Monty Python land, "and now for something completely different." Enough of this silly math and color science stuff, ok? How about something fun for a change?

My wife and I got a Brazilian earworm the other day [1]. An earworm is one of those catchy tunes that gets stuck in your head. Since my wife and I are both susceptible to earworms, and both like to sing, and spend a lot of time together, we generally spend weeks re-infecting each other with earworms. The only way to get rid of an earworm in our household is to introduce another.

The earworm was the song "Brazil".

Here is a version of the song which I would call quintessential. And I say that not as a real expert, but as a guy who likes the song, and who once had a collection of over twenty eight track tapes, so I consider myself an expert musicologist. The music in this video is hot, the tempo is fast, and its got lots of instrumental things going on. You know, like a piano and stuff. Maybe strings and those things that you shake to make shikka-shikka sounds.



This version was from the movie The Eddy Duchin Story, which was about a band leader from the 30's and 40's. I forget the band leader's name, but the movie is his story. You can buy the soundtrack of the movie from Amazon.

This is not the original version of the song, of course. That would have been back in 1939, when it was written one stormy night by Ary Barrosa. The first recording of it was by Francisco Alves, which I have painstakingly cut and pasted from YouTube below. Comparing this to the version from the Eddy Duchin movie, you will note two things. First, it's slower - still a reasonable tempo, but not frenetic. The second thing is that there are words! The cool thing is that the words are in Portuguese, which (in my opinion) is an absolutely gorgeous, sensual language. I am sure if I knew how to speak Portuguese, I would have better luck with the women, if I were single. And, of course, if I chose to use that secret weapon.



As lovely as this version is (in it's tinny kind of 1939 recording quality way, and with its 1939 kind of vocal stylings), the version that put Brazil on the map [2] was an animated version by Disney. Donald Duck is in the cartoon, but the singer is a parrot by the name of Joe Carioca [3], as sung by the real life human Jose Oliveria.

Donald and Joe

Here is the YouTube video. I recommend watching it from one end to the other. The idea of animating the painting of the scenes with a paintbrush was truly inspired. The inspiration actually comes from the full title of the song, "Aqualera do Brasil", which means "Watercolor of Brazil". Barrosa came up with the name when he looked at a watercolor painting by that name.



There are 2^n (cos (zillion) + exp (umpti-leven/2)) versions of this song on YouTube. I listened to quite a few, but I must admit, my research was not exhaustive. Still, here are some that stuck out in my mind.

I start off with one of the absolute worst versions, as performed by the Ray Conniff Singers. Sorry, Ray, this version just leaves me flat. They slowed it down and turned it into a 1970's fashion statement. I am the singer on the far left, by the way. I still have the bow tie, but my barber left town.



Contrast this against the Lawrence Welk version from 1959. Now, I grew up being indoctrinated in the belief that Lawrence Welk was totally unhip "Gramma music". If you were indoctrinated the same way, this clip might change your mind. Electric guitar, muted horns playing a crisp staccato, joined by flutes and clarinets... all at an electrifying tempo. And what would a Lawrence Welk song be without the accordion of Myron Floren? Seriously, this rocks.



Just to be clear about my own tastes, the song doesn't have to be performed fast to make me long for the sandy beach and skimpy bikinis of Rio. Here is a version from old Blue Eyes that pops my cork. Note that he never bothered with the Portuguese lyrics [4]. I guess he figgered he was sexy enough already.



And here is another laid back version that I can't help dooby-do-wopping along to.



Finally, I provide a version by the Slovenian vocal group Perpetuum Jazzile. (See if you can find me in the second row.) I can't watch this video without wondering what kind of volume discount [5] they get on the Shure SM58 mics. And the volume discount on Prozac.



----------------------------------
[1] I know what you are thinking. Not that kind of Brazilian! An earworm, silly.

[2] "Put Brazil on the map" Isn't that a cute little pun?

[3] This last name sounded to me a lot like "karaoke", so I had to dig around a bit. Is there any connection? Well, of course not. "Carioca" is a Brazilian word referring to people from Rio de Janeiro. The word "karaoke" is a Japanese word meaning, literally "empty orchestra". No connection other than the serendipitity of two words sounding similar and relating to singing.

[4] Here are the English lyrics that Sinatra sings:

Brazil, where hearts were entertaining June
We stood beneath an amber moon
And softly murmured someday soon
We kissed and clung together

Then, tomorrow was another day
Morning found me miles away
With still a million things to say
Now, when twilight dims the sky above
Recalling thrills of our love
There's one thing I'm certain of
Return I will to old Brazil

(instrumental)

Then, tomorrow was another day
Morning found me miles away
With still a million things to say
Now, when twilight dims the sky above
Recalling thrills of our love
There's one thing that I'm certain of
Return I will to old Brazil
That old Brazil
Man, it's old in Brazil
Brazil, Brazil

[5] "Volume discount" - another incredibly subtle pun.

Thursday, September 12, 2013

How many colors are there - the definitive answer

Here is the quick summary: There are 346,005 discernible colors.

I published a rather popular blog post in October 2012 that posed the slightly whimsical question "How many color are in your rainbow?"  I looked at the question in a number of ways and came up with answers anywhere from 3 to 16,777,216. The intent of the post was to collect some interesting facts into one coherent and entertaining post.

But, I sort of sidestepped the implied question: How many discernible colors are there?  I intend in this post to answer the question a bit more scientifically. Well... quite a bit more scientifically. For this blog post, I used a Monte Carlo technique to determine the volume of CIELAB space, and then modified this volume according to DE00 to account for the nonlinearity of CIELAB. And the number 346,005 plopped out.

General idea

I started by generating zillions of random spectra [1]. Now, I'm not gonna say that I generated every spectra possible. I'm sure I missed a few that were hiding down there in the shadows. But I did look at a whole bunch of them. Half a billion, to be exact.

I converted each spectra into L*a*b* values using D50 illumination and the 2° observer. The resulting L*a*b* values were tabulated into boxes in a three-dimensional array, with each box indicating whether the corresponding region in CIELAB space contained a viable L*a*b* value.  

Next, I counted up the number of boxes checked to establish the volume of CIELAB space. According to my experiment, the volume is just short of 2.2 million. This number fits in reasonably well with two papers cited by Gary Field in my addendum blog post:

Research on the number of colors issue usually starts with reference to the Dorothy Nickerson and Sidney Newhall paper of 1943 (JOSA, pp. 419-422). They conclude that there are about 7,500,000 surface colors at "supraliminal" viewing conditions, and 1,875,000 colors when viewing conditions approximate those used for color matching work.

Mike Pointer and Geoff Attridge concluded that there were about 2,280,000 discernible colors in their 1998 CR&A article (pp. 52-54). 

Thus, my number (2.176 million) corroborates the previous results from Nickerson and Newhall (1.875 million), and from Pointer and Attridge (2.280 million).

But we're not done yet. As we know, CIELAB is just not all that uniform. In particular, two saturated yellow colors might be 5 units apart (according to DEab) but might still be perceived by a human as just barely different. Thus, this figure is an overestimate of the number of colors that are actually discernible. Since I have all (or nearly all) the physically realizable colors in boxes, I can compute the volume of each box using DE00. Adding the DE00 volumes of each of the boxes will provide an estimate of the true number of colors, corrected for visual linearity.

Based on this correction, the number of discernible colors is 346,005. I won't attempt to name them in this blog post. That will come in a future post.

Now for some details on how the calculation was done...

Generating spectra

All the spectra were "physically realizable reluctance spectra", which is to say, the reflectance values were all between 0 and 100%. I created spectra from 380 nm to 730 nm, in 10 nm increments. All the spectra I generated were somewhat "smooth", in that they were piece-wise linear functions. I show one example below.


The spectra above is comprised of nine segments. I generated 125 million of these nine-segment spectra, along with the same number of spectra with eight segments, the same number with seven segments, and the same number with six. Thus, there were 500 million spectra en toto.

Initially, I used reflectance values that were uniformly distributed between 0 and 100%. This proved a bit slow to converge (slow to fill the area), since a lot of spectra were generated at the light end where our sensitivity to color difference is rather weak. For this final work, I used random numbers distributed according to the cube root distribution. 

Caveat - This Monte Carlo analysis necessarily will produce only a subset of all possible spectra. First, discontinuous spectra were left out. Second, the fact that "only" half a billion spectra were analyzed leaves open the possibility that some are missed. This would tend to cause my estimate to be a bit low.

I also tried generating purely random spectra, with no correlation between wavelengths. Initially this was slow to converge - perhaps that might have worked out in the long run if I would have just had the patience.

Tallying the number of unique colors

A three dimensional array was created, representing L* values from 0 to 100, a* values from -150 to + 150, and b* values from -150 to +150. All three dimensions were quantized in steps of 5, resulting in 21 X 61 X 61 boxes. Thus, there was a single cube, for example, in CIELAB space representing all colors in the range 20 < L* < 25, -40 < a* < -35, and 80 < b* < 85.

Each of the spectra were converted to CIELAB values using the D50 light source and the 2° observer. The CIELAB values were then converted to a position in the three dimensional array, and the location was marked to indicate that there was at least one viable CIELAB value within the box.

If anyone is interested, I can send you a list of the centers of all the boxes, representing all valid CIELAB colors. Send me an email at john@johnthemathguy.com. If anyone is really interested, I can provide a set of very colorful charts like the one below, that summarize all this data. If enough people are really interested, I will post those to my website for all to marvel at.

Viable a*b* values in the range 55 < L* < 60
(each square represents a 5 X 5 box in a*b*)

Caveat - This discretization causes a bit of an error. It will cause an over-estimation of the number of colors. Why? Let's say that a certain box is at the edge of color space, straddling the line between viable CIELAB values and silly-lab values. If zillions of spectra are tested, then this box will eventually get a tally, despite the fact that only half of its volume should have been counted.

Converting to a count of discernible colors

Now for the novel part, the conversion to DE00. In the previous analysis, the tacit assumption was made that each of those 5 X 5 X 5 boxes had a volume of 125. To be completely correct, the volume of each cube is 125 ΔEab3, cubic delta E units. I guess maybe that's not an assumption, that is pretty much just geometry. The assumption comes in when this is interpreted as meaning that each box contains 125 discernible colors. Those who have subscribed to the Color Science Times Newspaper for the last 30 years know that this might not be exactly the case.

So, I computed the volume using a color difference formula that is closer to human visual perception, ΔE00. Theoretically, we could just compute the volume of a box by determining the color difference from top to bottom, from side to side, and from other side to other side. These three numbers would be multiplied together to get the volume of discernible colors in that box. This is reasonable, but it falls just outside of the spec for this color difference. Due to nonlinearity, the warranty on ΔE00 expires at 4. Beyond that point, it may not give reasonable results.

Just to make sure this didn't introduce an error, I divided the cube into eight cubes, each with sides of 2.5 ΔEab, and added these up. Now we are within the warranty.

346,005. I'm going to use this for all my computer passwords. Just to make sure I remember it.

---------------------

[1] I am talking here in the first person, like I actually generated all the spectra myself. I didn't really. I have better things to do. Like drink beer. I had my assistant Dell Studio generate the spectra. He didn't seem to mind, although he did seem to take his time about it. 



Wednesday, September 4, 2013

Mixing my ink with my beer

I have had a lot to say in the John the Math Guy blog about beer. There was a recent post about ruminations on beer, but the key post on beer, my seminal post on beer, is the post where I cleverly used beer to illustrate Beer's law. I keep going back to that one because I just can't get over how brilliant the idea was.

I have referred to this Beer's law post in heaps and gobs of other posts:


Green ink being shamelessly added to beer

Several people have asked questions on this Beer's law thing, and how it connects with ink. Way back in January (2013), I got an email from a PhD student in the UK:

When I scoured the internet for the derivation of this equation I only found the original equation based on absorption coefficient, path length and concentration.

I would like to understand where the alternative equation is coming from. Could you point me in the direction of a useful paper or similar? Any help would very much be appreciated. Thanks a lot in advance.

Kind regards,
Anja

I just recently got a similar question from Michael, who is not a PhD student in the UK, but is nonetheless a smart guy. He just aced the Science and Technology Quiz that was put together by Smithsonian magazine and the Per Research Center. This is quite an accomplishment. I'm proud to be a "virtual" friend of yours, Michael.

I thought Beers law was related to transmission of light through something, not reflected - but, well, same difference ?

Michael's question came to me on through that website that everyone uses for scientific collaboration.: FaceBook. If you haven't heard of it yet, I suggest you check it out. That's where I do most of my serious research.

The plethora of questions (there were two...) show that I have clearly messed up big time in my desire to educate the world about ink and beer. I left one little step out, the mixing of ink and beer. Just how is it that Beer's law applies to ink?
Beer (on the left) and ink (on the right)

Ink is soooo not like paint

One of those wonderful things that we can count on in this world is that paint is not like ink. Oh... they may seem the same to the untrained and unscientific eye. You put them on something and it changes the color. But there is one key difference, as illustrated in the image below.

This time, paint is on the left and ink (on the right)

This image was created by smearing ink and paint on a sheet of paper [3]. Before smearing, a large black area was printed on the sheet. Note that on the left, the paint completely obliterates the black underneath. Paint has a great hiding power, at least when you pay more than $8 a gallon for it. The ink, however, does a perfectly lousy job of hiding the black. You really can't tell that the yellow ink is overneath the black.

What gives? Is ink just really, really cheap paint? Oh contraire! Let me assure you, ink does a pretty decent job of doing exactly what it was trained to do. And paint also does a pretty decent job at what it was trained to do. That is, if you aren't cheap like me, buying the ultra-cheap paint at $8 a gallon from Fast Eddie's Paint Emporium and Car Wash.

The actual photomicrograph below illustrates what an ideal cyan ink is trained to do. Red, green, and blue light hit the surface of the ink. [4] As can be seen, the blue and green light go right through the cyan filter ink. The ink is transparent to green and blue light. These two flavors of light hit the paper (or other white print substrate) and reflect back. Why? Cuz the substrate is white, and that's what white things are trained to do. 


Cyan ink, sitting contentedly on paper while being bombarded with red, green, and blue light

The red light suffers a completely different fate. For anyone who has visited a red light district, this should be no surprise that one's fate may change. The red light is absorbed by the cyan ink. Few of the poor hapless red photons ever even get a chance to reach the paper, and even fewer make it through the ink in the hazardous journey back through.

I may have shattered some illusions about ink here. I apologize, but it's time you learned the facts about the birds and the bees and the inks. It is customary to think of light just reflecting off the ink. Sorry. It's more complicated than that. The only reflecting that's done is done by the paper.

Ink is a filter, a filter laid atop the paper.

Why is ink that way?

This bizarre behavior is not just some side effect of some bizarre organic chemistry that is only understood by some bizarre color scientist locked in the lab at Sun Chemical. This bizarre behavior is a property that is specifically engineered by some some bizarre color scientist locked in the lab at Sun Chemical. 

To see why this would be a good thing to engineer in, consider what happens when magenta ink is placed overneath cyan ink. Magenta ink works a lot like cyan ink, except that it absorbs green light and passes red and blue. The excitement starts when you put on ink on the other. The cyan ink absorbs red light and the magenta ink absorbs the green. What's left? Just blue light.

Magenta ink, sitting contentedly on cyan ink

The exciting part of this is that new colors are created. We start with cyan, magenta, and yellow inks. By putting one ink overneath another, the additional colors red, green, and blue are created. Try doing that with paint! It ain't gonna work. The paint on top defines the color, hiding whatever is below. 

This feature of ink is what allows us to have a much wider gamut. With three inks (cyan, magenta, and yellow) we can theoretically get eight different colors: white (no ink), cyan, magenta, yellow, red, green, blue, and black (all three inks).

Getting a bit more quantitative

I need to put some numbers on this if I'm going to get Beer's law involved. I painted a rather black and white picture of cyan. Well, ok, I should say that I inked a black and white picture rather than painted it. And black and white aren't quite the correct colors. But, the point is, inks are not perfect. Cyan does not capture all the red photons. Nor does it pass all the green and blue photons.

 A typical cyan ink might allow 20% of the red photons to pass through on their way to the substrate. That is, 80% of the red light gets absorbed and the other 20% makes it down to the paper. Let's just assume that all of those photons reflect from the paper. (I am telling a little white lie here, but it's for a good purpose.) 

Ok, so if we start out with 100 red photons heading downward into the ink, 20 of them will reach the paper. Of these 20, 80% of them (I think that would be 16) will get absorbed on the way up. That leaves just 4 red photons, out of the original 100, that make it back out. For those of you who are all into the density thing, this would mean about 1.40D. If you understood that, then you know Beer's law, and can apply it to ink on paper. Who said that ink and beer don't mix?

--------------------------
[1] You may have seen this blog post in Flexo Global Magazine. So, we are talking popular here.

[2] I am pleased to say that this blog post was picked up just recently by the Australia New Zealand Flexographic Technical Association magazine (August 2013). Look for it in your mailbox. This blog post was also picked up by Flexo Global magazine. So... we are talking really popular here.

[3] Truth in advertising here... this is not an actual photo, but a digital simulation. It is very nearly photorealistic due to my vast artistic ability, and it simulates what really happens, but I repeat, this is not an actual photo.

[4] Someday I will get around to writing a blog about how light comes in three flavors: red, green, and blue. That's all. All other colors are a combination of those three. Based on this simplification, you can explain why inks are CMY and computer monitors are RGB. It will be a totally cool blog. I will send you a text when I finally publish it.