23.6.14

50 Shades Of Grey

No, not those 50 shades of grey so put it away please. Ladies, you too.
I never actually read that book; all I know is British people turn red when someone mentions it, which means there's probably some French kissing involved.



This is an ode to the grey colour and its many shades. I was moved to write this ode after nailing the "Emulate the Kodak HIE film effects in a digital post-processing filter" problem: a problem so elusive, so hard to solve. Or so I thought before I came across the 50 different greyscale spaces I could create with minimum effort. One if these spaces gives the same magical effects typically observed in Kodak HIE photos. More on that in a second.

Kodak HIE photos are remarkable. In addition to turning ordinary landscapes into achromatic masterpieces, Kodak HIE film is perfect for turning tired old people into refreshed spring chickens without the need for extra image processing. Which is why I always remember Kodak HIE with fondness when airline employees ask me to check out my under eye bags because they're too big to carry with me.

Over the last few years I have tried to replicate the effects of Kodak HIE film with pixels. Because why not. I tried brute forcing it by approximating the primaries. I also tried flattening the colour space, converting from rgb to hsl, and playing with the hues (an idea which came to me at the worst possible time while doing a job interview). Nothing produced quality results.

Then one day a few days ago while playing with my phone's built in photo filters, I realized that one of these filters produces approximately the same effect as a photo from Kodak HIE film. The filter was simply called "Noir", which led me to believe that the good people who made this filter were most likely totally oblivious to the groundbreaking work that they were working on as it often happens.

Groundbreaking because I says so. In their minds they were probably thinking they were only making yet another black and white filter for the vainies and the selfiers. But it was much, much more than this. In my mind these people are right up there with whoever realized that the best way to build a flying machine is not by emulating what birds do but by studying why they do it and thus the study of aerodynamics was born.

So why is Kodak HIE film visibly different even though the human eye can't perceive infrared and why does the Noir filter act so similar according to my eyeballs? I can't look at Noir's proprietary code; I can only take a look at the final results and guess.

At first glance it appears that it's just cranking up the contrast before converting to greyscale. That's what I'm doing with the Glamour Greyscale filter on Coloroid and yet it doesn't seem to be enough to make photos look like I just spent a lot of money on a special Kodak film.

So what else is happening there? I remembered reading about the colour space used by the first televisions and how different one greyscale could be from another. It was a vague memory but enough to point me in the right direction.

The function to turn RGB into grayscale is not unique. The image below clearly illustrates this. It sports 3 different grayscale spaces: the selfie on the far left is the type you'd see on your TV today playing an old B&W movie, the one in the middle is the Noir filter on my phone, and the one on the right is infrared-ish.  All of the frames are high on contrast and low on brightness, the exact same amount in each case.
 From my husband's series "My Wife fully clothed in front of Other People's Artwork".
Just like different physical filters can be used to produce different shades of grey simply by putting less weight on the reds, the blues, and the greens, I can run each pixel through a post-processing function where I can alter the linear intensity of each of the RGB primaries effectively changing the shades of grey within an image. The function below returns the relative luminance, which is then used to generate the achromatic space.

function shadeOfGrey(r, g, b, x, y, z)
{
return ((r*x)+(g*y)+(b*z));
}

Where (r*x) < 1 is the linear intensity of the red value of the pixel, (g*y) <1 is the linear intensity of the green value and so on. And also by construction, the sum  x + y + z = 1

So for example, here's the greyscale function used by old school TVs:

function secamYIV(r,g,b)
{
return ((r*0.299)+(g*0.587)+(b*0.114));
}

And here's the greyscale function used by modern TVs

function hdtvITUR($r,$g,$b)
{
return (($r*0.213)+($g*0.715)+($b*0.072));
}

The coefficients in the hdtvITUR function above represent the average intensity perception of people with regular colour vision: green light dominates the intensity perceived by humans, followed by red light and blue light is last.

I imagine in Noir's function the red coefficient is the predominant one, closely followed by the green one, and the blue is very small ~0.

function noir($r,$g,$b)
{
return (($r*0.699)+($g*0.300)+($b*0.001));
}

This is why Noir resembles the effects of Kodak HIE film: because in Kodak HIE photos blue wavelengths are reflected, which is why I was so desperate to tamper with the blue values of pixels in the first place, although I was coming at it the wrong way.

Well, I said that one day I would solve this problem and I did

/* -------------------------------------------------  
 This content is released under the GNU License    
 Author: Marina Ibrishimova (http://ibrius.net)  
 Version: 1.0  
 ---------------------------------------------------- */ 
function hie_greyscale($r,$g,$b)   
 {  
      return (($r*0.998)+($g*0.001)+($b*0.001));  
 }     



My first digital near infrared-ish masterpiece with my very own filter. Ole!

The "original"

This filter is coming soon on Coloroid.  This filter is now on Coloroid in Photo Filters -> Infraredian below Glamorous Greyscale.