Monday, September 20, 2010

Over and Under Exposure

GETTING EXPOSURE RIGHT is one of the challenges — and annoyances — of photography. I had long experience with black and white film photography and so I thought I had a pretty good understanding of exposure and how to get a decently-exposed image. When I got into digital photography back in 2001, I was quite disappointed with the results — the automatic exposure was often very wrong among other problems — and I had the bad opinion that it was the camera's job to set itself properly. You can read more of this on my old posting A Camera Diary.

Besides thinking that good photography merely involves choosing the ‘best’ camera, I was quite naïve about the properties of color digital images, and how they differ from black and white film. Exposure is far more critical to color photography relative to black and white.

Please consider the following series of images, taken at ISO 200, f/8, with each exposure time varying from 1/8th for the darkest, to 8 seconds for the brightest. This Beaux-Arts building was built in 1900 for the Saint Louis Club, later became the headquarters for the Woolworth's company, and now houses the Saint Louis University Museum of Art.

Saint Louis University, in Saint Louis, Missouri, USA - Saint Louis University Museum of Art at dawn - side-by-side composite of 4 exposures

Which image is exposed the best? Certainly exposure is something of a matter of taste, and your particular monitor settings may make one look better than another, and you might change your opinion if you used a different computer or if you printed these. However, too much exposure will give you all white, and too little exposure will give you black, and then you no longer have an image of a building. Objectively speaking, you have to expose within a specific range, which will vary depending on subject matter, your camera, and your post-processing.

If I had to choose between these four images, I'd select either the upper right hand image, or the lower left hand one; although I think that an intermediate exposure between these two would have been better. I took this in the morning, and perhaps I ought to have waited a few minutes for the sky to get brighter, which would have given a better balance of light over the entire image.

OK, I might say that I'll choose whatever image looks best to me; of course you do have to do that. Just because a machine says that one image is better than another doesn't mean that we have to follow that advice, because photographs are intended for humans, not machines. Just because the camera says that the photograph is correctly exposed doesn't mean that it will look best to us. But limiting ourselves to just gut instinct can't be right: “The unexamined life is not worth living for a human being” wrote Plato in the Apology. Instead, we ought to ask some questions. Why does one image look better than another? How can we reliably and predictably make good images?

Just because an image appears to be a bit dark does not mean that it is bad — there is a lot of detail that can be pulled up from the shadows. Generally, overexposure is more of a problem with digital images than underexposure, and so the standard advice is to expose for the highlights and process for the shadows. By the way, this is opposite to the advice used for shooting film negatives, where you generally have to expose to get good shadow detail.

Let's pull up some shadow detail from the upper right hand image:

Saint Louis University, in Saint Louis, Missouri, USA - Saint Louis University Museum of Art at dawn - lightened shadows

I think this is an adequate image. Lots of detail is normally lost in the shadows, and it is easy to make this detail visible. This is just a rough brightening, and there are lots of techniques to show good detail in shadows. Were I doing a better job, I'd add more local contrast in the shadows; these shadows look a bit flat.

My intention when taking these photos was to produce a series of images which I would later blend together to make decent single image with lots of highlight and shadow detail with little noise and good color rendition. Before I submit the images to my exposure-blending software, I create hard exposure masks which cut off those parts of the images which are over- and under-exposed; the end result is a nicer looking image with low noise and good color tone. Without these masks, the software produces unpleasant color shifts in the highlights and excessive noise in the shadows. Masking also reduces haloing artifacts generated by my software.

Overexposure

It would be helpful if we define our terms. A pixel in an image is overexposed if any one of the three color channels is at its maximum value; or for eight bit images, if any channel is equal to 255. Now 255 might just happen to be the correct value of a pixel, but that is unlikely, since everything brighter will be equal to 255 also. If any one of the three color channels clips due to overexposure, then you will get color shifts in the final image.

This color shift is rather prominent on the brightest of my sample images.  Here is a close up view; note how the color of the building near the light goes from a nice orange color to yellow, and then white; while the blue sign goes to cyan then white:

Saint Louis University, in Saint Louis, Missouri, USA - Saint Louis University Museum of Art at dawn - overexposure masks

In the upper right hand corner, I put in black wherever any one of the three color channels of a pixel is equal to 255. In the lower left hand corner is a mask which shows wherever the RGB luminosity goes to 255; notice how it masks out a smaller area than the full overexposure mask.

RGB luminosity is roughly defined as:
30% Red + 59% Green + 11% Blue
This approximates the sensitivity our eyes have to each primary color.  But this value will often be less than 255, even if one of the channels is overexposed. Some camera histograms will show this value instead of three individual color histograms, which can be less than helpful. Also, some exposure blending and tone-mapping methods use this value as an estimate of brightness, and the final images often show these color shifts.

In the lower right hand corner I superimposed the full overexposure mask on the image. Note that it covers up nearly all of the areas that show an obvious color shift, but not all.  There appears to be some bad color bleeding out from around the edges of the mask.

This image, even though it comes from a Camera RAW file, still has been highly processed by the RAW converter, plus I did some lens distortion correction as well as straightening of the image. My camera uses a matrix of light sensors, and each one is sensitive to only one color.  When the RAW converter makes the final image, it estimates the missing colors at each pixel by examining neighboring pixels. Likewise, when correcting for lens distortion and camera tilt, Photoshop estimates the correct pixel values by also examining neighboring values.  So we are always doing some averaging; but consider this example equation:
Estimated value = (250+240+235+garbage)/4 = garbage
So the effects of overexposure anywhere in an image will spread a bit to neighboring pixels. In practice, when I make a mask like this, I will mask out everything that has a value over 250 or so, which seems to get rid of most if not all of these nominally good, but actually bad pixels, without losing too much highlight detail. Someday I'd like to see software that offers a mask channel associated with images, which will show all pixels which are overexposed, or which are indirectly unreliable due to processing.

Here is the brightest image, with a black overexposure mask superimposed on it:

Saint Louis University, in Saint Louis, Missouri, USA - Saint Louis University Museum of Art at dawn - extended overexposure mask

I extended the mask a little bit, so as to eliminate the color shift which extends a few pixels beyond the measurably overexposed parts. Note that the sky is masked out, because it is completely overexposed in the blue channel. About 1/3rd of the image is overexposed. There is good detail throughout the rest of the image. Note that there is a slight blue halo around the roofline; this is because this image is not particularly sharp, and so there is a bit of blur along edges which does not get masked out.

Photography has many trade-offs, requiring us to make choices; we neither want to overexpose, nor do we want to underexpose. Ultimately, some detail doesn't matter, and specular highlights and light sources are usually considered unimportant — it is OK to overexpose them most of the time, as we see even in our darkest example photo above. The lights aren't the obvious subject of the photo.

Now if you have large areas of color in your photo, you probably don't want to overexpose them, even if they aren't the subject. Digital cameras will often overexpose blue skies, which I think is objectionable most of the time, even if it is not the subject of the photograph.  This kind of overexposure is particularly objectionable when the sky goes from blue to cyan to white in a single image: that just doesn't look natural. See my article Three Opportunities for Overexposure. Alternatively, it is often best to strongly overexpose a background, turning it a pure color or white, rather than having a muddled partial overexposure with obvious color shifts.

Another problem with overexposure, besides color shift, is that it removes texture from the image. Areas with even one channel overexposed will appear somewhat flat. Now there are techniques which you can use to rescue such overexposed images, by generating plausible detail from the remaining channels. This is difficult to do correctly, and is time-consuming.

Now technique ought to serve the subject matter; the subject does not serve the technique except perhaps when you are creating images for teaching. Just because the blue channel of the sky in an image is overexposed does not mean that you can't end up with a terrific photograph, if the subject is worthy.

Underexposure

Defining overexposure is easy, even if we have to be careful and realize that it isn't quite as simple as we would like. Defining underexposure is far more problematic.

I defined overexposure on any given pixel as the situation where any one channel is at its maximum value, generally equal to 255 with 8 bit images. OK, we can naïvely assume that underexposure is the situation where any color channel equals 0. For example:

Saint Louis University, in Saint Louis, Missouri, USA - Saint Louis University Museum of Art at dawn - naïve underexposure mask

Not much of a mask at the bottom. This is next to worthless, just a few black dots here and there, even though there is a lot of black in this image. There are several problems with our effort here, the most significant is that there is a tremendous amount of noise, relatively speaking, that is found in the darkest part of the image, often due to the quantum fluctuation of light. Light is detected in discrete quantities due to a mysterious property of matter and energy on a small scale, and therefore is quite non-uniform.  There are also several sources of noise in the camera itself, and these sources will add to the signal, moving it away from zero. Also consider the indirect problem mentioned with overexposure: image manipulation will ‘infect’ neighboring pixels, and since no pixel value can be less than zero, this averaging will only increase the value found at pixels which ought to be zero. Noise at low levels does not average out to zero, but instead will brighten dark pixels..

Some cameras, as well as RAW converters, will do plenty of image manipulation including noise reduction or black-point cutoff, making our low-value pixels even more unreliable.

Instead I use a working definition of underexposure which masks out those values near zero. Now, should I take into account all three color channels at one time, or each color channel separately? If I choose all three, then I might not mask out a particular poor, noisy channel if the other two are good.

But if I mask out each channel separately, then I might get the situation where a particular pixel is both overexposed and underexposed! I often see this with stained glass. For a particularly brilliant red piece of glass, I may have the Red channel at 255, while the Blue channel is at 0: this indicates that the color is particularly pure and outside of the color gamut of the camera or color space used in Photoshop.

There are several methods I use to mask out dark noise.  The simplest uses the image itself and the Threshold slider; this uses the RGB luminance function shown above. I examine the image while moving Threshold, and stop when a reasonable amount of noise is eliminated.  Using this process on our darkest sample image we see:

Saint Louis University, in Saint Louis, Missouri, USA - Saint Louis University Museum of Art at dawn - underexposure mask detail

The road and the top of the building on the left shows the most noise. I adjusted the Threshold slider until much of that noise is eliminated, as you can see on this detail from the lower right hand corner of the image. You don't want to do too much of this.

I also use the same process, but doing each channel independently. This makes an exceptionally clean final image, but only if we don't have the simultaneous over and under exposure problem mentioned above.

Saint Louis University, in Saint Louis, Missouri, USA - Saint Louis University Museum of Art at dawn - three channel underexposure mask

This looks like a pretty good mask. It masks out the most underexposed parts of the image while not showing too much residual noise.

There is another technique which illustrates the problem of dark noise quite dramatically. What I do is take each channel separately, and brighten it with Curves until it no longer appears to be a photograph, but rather a line and charcoal drawing. Instead of a nice apparently continuous series of tones, we get discrete steps. This shows that we don't have enough spacing between brightness levels to produce a good image. Usually this effect is most prominent in the Blue channel because normal in-camera processing greatly amplifies its shadows.

Saint Louis University, in Saint Louis, Missouri, USA - Saint Louis University Museum of Art at dawn - line-drawing effect

You may want to click on the image to see the full size version. Some image enhancement software will work quite hard to bring out detail in shadows, but this is certainly detail we don't want to emphasize — unless of course we are going for a cartoony look. As it happens in this image, the red and green channels don't quite go to zero much and so we don't get much of the line drawing effect, but the blue channel does; so our mask eliminates considerable amounts of noise.

Creating masks like these can show you how much of your image consists of high quality pixels. I use these also for creating exposure blends. Here are those four images blended together, masking out the big color shifts and dark noise:

Saint Louis University, in Saint Louis, Missouri, USA - Saint Louis University Museum of Art at dawn

It looks pretty good, and there are hardly any color shifts except for the areas which were overexposed on the darkest base image. Notably, the color on the building and the blue sign have uniform color as needed, and we have excellent detail in the shadows. The major artifact here is the sidewalk light to the right of the stairs:  it turned off between the second and third photos and so we get a strange rendering of it here. There is also some roughness along the roofline.  You can click on the image to see the full resolution version.

Conclusion

The phenomenon of color shift — when even one channel is overexposed — severely limits quality color photography.  Of course, solid studio lighting, or supplemental lighting with fill-in reflectors are frequently used by quality photographers. Or, you can blend multiple exposures, but then the problem is finding the right algorithm or software to do this.

On the contrary, this color problem implies that quality black and white photographs ought to be easier to produce. We can introduce severe changes of contrast without worrying about color shifts.

Sunday, September 5, 2010

Imaginary and Impossible Colors

STARE AT THE TOP square for a minute or more. Do not move your head, and keep your eyes right in the middle of the square.

Slowly move your eyes to the square below.

Imaginary colors

Glorious, isn't it?

You are seeing some colors that are impossible to actually portray in the real world, other than transiently as you see here. These are called “imaginary colors”. You can't make paint that shows those colors, nor can you project a color of that light on a screen, nor show it on a computer monitor. A color meter does not measure these colors.

Here is the problem.  The human eye has basically three classes of color sensors or cone cells, one generally sensitive to the red side of the color spectrum, another sensitive to blue on the other side of the spectrum, and green in the middle, along with green-blue sensitive rod cells that work most prominently in dim lighting. There are three color sensors, three only (although there may be some people — probably females only — who have four classes, and very many males, mostly, who have less than three).

There are some deep, rich red colors which do not stimulate either your green or blue cone cells.  There are some deep, rich, dark violet colors which do not stimulate green or red.  However, there are no green colors whatsoever which do not also stimulate your red or blue cells, or even both.

A camera mimics human vision by also having three classes of sensors, and like the eye, there is no color which will give a signal in the camera's green which will not also give a signal in either red or blue or both. There will be of course reds without blue and blues without red. You can examine your own RAW photos with the excellent RAW Photo Processor, set so as to do minimal processing of the image.

Unprocessed RGB

RAW Photo Processor was set with UniWB and no color space assigned, which gives basically the actual signal received by the pixels. No green colors have a dark red or blue signal. That we mathematically represent a pure bright green color in the sRGB color system as Red=0, Green=255, and Blue=0 tells us very little as to how the eye or camera senses the color: you'll never get a green signal without significant amounts of either red or blue or both.

Human color vision as it is has the potential to see these supergreen colors, unadulterated with excess red or blue. Our experiment above shows that you can actually see these colors, if only for a brief moment. Individuals with synesthesia or severe migraine headaches can see them more often.

Apparently, when we stare at a color long enough, our eyes become ‘fatigued’ and lose sensitivity to that color. Staring at the red-blue colors leads to decreased sensitivity to them — and so we can see, ever so briefly, imaginary supergreen. However, I suspect that this mechanism is responsible for the automatic white balance of the eye. We can see gray tones correctly under a wide variety of lighting, while a camera set to a fixed white balance would not, and so the eye must have some mechanism of subtracting out the color of the light.

Since we generally have only three types of color sensors in our eyes, which have well-characterized properties of light absorption, we have the basis for creating a precise mathematical model of color: and this model will have precisely three coordinates. This is despite the intense processing that goes on in our eyes and brains; processing that is hardly known at all, despite the fact that we experience it all of the time. That it is often difficult to put our experiences into words does not mean that we ought not attempt that work.

Following is a chart which represents the full gamut of real saturated colors seen by human vision:

Cie_Chart_with_sRGB_gamut_by_spigget

Image originally from Wikipedia. Source and attribution is here.

This image approximately illustrates the full range of midtone saturated colors that can be actually reproduced by paint or by colored lights. Notice the straight line between blue and red? That shows that we can in fact get pure red and blue tones, not adulterated by any green at all, along with purple and scarlet mixtures of the two colors. Notice that the hump in the curve is in the green region, which shows that there is no physical green color which is not also a bit red or blue. If a supergreen color actually existed, then this chart would be a perfect triangle.  Full human color imagination, including the supergreen colors, very likely is a triangle — for we can predict quite accurately what kind of supercolor we will see in experiments like the one above.

The color gamut shown above is only approximate in color, because the image itself is limited to the gamut of the sRGB color system, which is itself represented by the small triangle inside of the big horseshoe. The corners of the triangle represent the primary colors used by sRGB.

sRGB is quite standard, and is used by most cameras, computer monitors, web browsers, and even High Definition Television, but it can only show about 35% of all possible physical colors, and tends to be lacking in purple, green, and cyan. By using excellent quality color filters, and a bright enough light source, you can display a much wider gamut of colors — the triangle will be bigger and fill up more of the horseshoe — and for a price you can buy a high-gamut monitor that can display more colors than the puny sRGB standard.

This particular standard was chosen by Microsoft and Hewlett-Packard because it works with even cheap computer monitors, and because it uses only 8 bits of data for each red, green, and blue color channel, which was a serious limitation back in the days of expensive computer memory. This standard gives us a large enough gamut of colors, with a small enough spacing between them to avoid banding artifacts. However, I always use 16 bits when working on my pictures — even though I have to eventually reduce them to 8 when I show them on the web. (Computers, by the way, are particularly efficient at using powers-of-two when manipulating data: so we often see 4 bits, 8 bits, 16 bits, 32 bits and so forth; always multiplying by two).

To display a color on a computer or by projection, you need at least three primary colors, and the particular colors you use, and their brightness, determine the final gamut. But notice that you have to use actual, real colors for your projector — they have to be within the horseshoe — and so there will always be colors that cannot be represented. If you want more gamut you eventually will have to add more colors, which is precisely what we see with high quality color printing. This is impractical with monitors, however, which are usually limited to just three primary colors.

In a sense, the three primary colors are a bit arbitrary, and artists have used a variety of primary color systems in their theory. However, some primary color systems are better than others because they have a larger color gamut, or can represent a larger variety of basic colors. Undoubtably, the bottom of the horseshoe is rather pristine, so I would expect that most any color system ought to attempt to get as close to the bottom corners as possible: the open question is to which third color to use. Do you want good greens or good cyans? You can't have both if you use just three colors.

Note that painters use subtractive colors, so their primary colors out of necessity will have to be the opposite of what is shown here: cyan, magenta, and yellow rather than red, green, and blue. In particular, the painters' primary color palette will be especially deficient of good blues, greens, and reds. This is why some pigment colors are highly prized by artists, since they have colors that are otherwise unmixable. In the ancient Mediterranean, the most costly dyes came from various species of Murex snails, and the colors produced were down at the bottom of the horseshoe chart — with the purple or scarlet colors being used for Imperial dress, and the blue used for the fringes of Jewish prayer shawls. These colors are decidedly non-mixable — you have to obtain a pure color and cannot obtain them by mixing other colors.

If you want to represent the entire gamut of colors mathematically, using only three numbers, then you have to go outside of the bounds of the horseshoe. But then some combinations will give colors that cannot be represented by any paint or filter. But remember that a supergreen color can actually be experienced under some circumstances. However, there are some wide-gamut color systems which represent colors that cannot exist even in our imaginations, like a scarlet black or deep blue white.  As far as I know a true wide-gamut color system that includes supergreen as one of its primaries does not exist, but it would be useful if it did, since it would closely represent the entire human visual system, including our imagination, while excluding those colors which are impossible to even imagine.

Here are the most commonly used color systems:
  • sRGB:  35% of entire gamut
  • ColorMatch RGB: a bit larger than sRGB, slightly different primaries
  • Adobe RGB:  50.6%
  • Wide-Gamut RGB:  77.6%
  • CMYK: smaller than sRGB, but not complete overlap.
  • ProPhoto RGB: most of the visible color gamut, 13% of the colors are imaginary or impossible.
  • L*a*b* colorspace: 100% of visible colors, with lots of impossible colors.
If you are a digital photographer, you have to choose a color system, and the question becomes which system to use.  Now sRGB is used everywhere, and is often the only color system that will look good on output: most devices just can't do much better than sRGB, and many output devices assume that sRGB is used.  If you output a wide-gamut file on an sRGB device, its colors will be muted, giving you precisely the opposite effect you desired.

Often I hear the advice that photographers ought to set their cameras to Adobe RGB, and just as often I hear photographers complain that their photos look washed out and unsaturated because they did use Adobe RGB but didn't know how to manage it, and so I recommend using sRGB and nothing else, even though it isn't the ‘best’.

When I do have need of producing colors outside of RGB, for example when preparing images for commercial four color print, then I will use a larger gamut color system, and eventually work directly in CMYK. If you are outputting to a broad-gamut color printer that uses more than four inks, then I'd use a high-gamut color system and load the color profile of the printer into Photoshop, keeping an eye on the gamut warning feature. If you are outputting images to the web, then use sRGB.

In the philosophy of logic, we say that a statement is true if it corresponds with being, with something that actually exists in the entire realm of being. But we say that a statement is meaningful if it does not encompass a logical contradiction — a square circle is not meaningful. If you can imagine something that does not actually exist — see it with your mind's eye — then your imagination still has meaning, even if it doesn't have truth. For example, you can imagine Doberman pincers with wings; these don't actually exist in our world, but you can imagine them without contradiction. Likewise with supergreen colors, which are meaningful even if you can't have a paint of that color.

Wednesday, August 18, 2010

Nikon View NX 2

NIKON RELEASED a new version of their free photo editing software: you can get it here: View NX 2.

In my opinion, this software produces better RAW conversions than does my version of Adobe Camera RAW with Photoshop CS3. I've noticed that it has much better color consistency between differently exposed images of the same subject, which is important for exposure blending — and it produces fewer noisy color artifacts along high-contrast edges. The colors also look much better, and the automatic color aberration removal is a time-saving feature.

But I can't wait to try ACR on Photoshop CS5 — when I can afford it.

A huge problem is that the old View NX is very slow, primarily because it uses lots of memory. The new NX 2 looks much better and has excellent performance. Now I can have all my applications open at one time without my computer grinding to a halt.

I use the D-Lighting feature all the time to boost shadows, but the old version just had a few settings — and the low setting often didn't work at all, or made things worse. The new version has a very smooth slider for continuous adjustment.

UPDATE: There appears to be a bug in the software.  When I make edits to a RAW file and save them, I do an output to TIFF, which then I pull into Photoshop for further editing.  THIS DOES NOT WORK. The TIFF file has the original RAW image, without the edits. Not good.

CORRECTION: The bug I saw is due to me previously editing the image in Adobe Camera RAW. This creates a sidecar file, which apparently confuses ViewNX.  If I delete that sidecar file — it has the file extension .xmp — ViewNX works properly.

Monday, August 16, 2010

An RGB Quiz

A LITTLE QUIZ. Guess the color channels in the photo below.

Color space RGB quiz

This is a photo of a hot air balloon, taken in a brilliant blue sky. We see here the three color channels of my original color image, along with a black-and-white conversion of the image, using the Photoshop Desaturate tool.


Please see my earlier posting, Color Spaces, Part 1: RGB. Mastering the channel structure of color images will give you more control over your final images, since it replaces guesswork and trial-and-error with certain knowledge.


Remember, in the RGB system we have one channel each for red, green, and blue light. For the red channel, if it is black, that means no red is present, and if white, then the red component of color is brightest, and likewise for the other two colors.

This was a typical blue sky, and so that is your only clue. See if you can answer these questions:
  1. What color is the balloon?
  2. What color are the stripes on the balloon?
  3. Actually, there is another band of a different color, near the top of the balloon. What is its color?
  4. Name each color channel.
  5. Identify the desaturated image.

Sunday, August 15, 2010

Color Spaces, Part 1: RGB

BLACK AND WHITE photography is a masterful medium. Despite — or perhaps because of — its simplicity, it really shows off a photographer's skill and eye. Digital black and white photography reflects this utter simplicity.  Each pixel in a final black and white JPEG image is assigned a value from 0, meaning pure black, to 255, meaning pure white. You can hardly get simpler than that and still call yourself a photographer.

But color is inherently messy. While we do know that most human eyes have three types of light-sensitive cone cells, which generally react to red, green, and blue light, this is a rather simplistic description of what actually exists. But what is really important is the fact that there are three types of color sensors. (And there is a fourth also, but it is sensitive to greenish-blue, and visually appears blue, and then typically only under dim lighting.)

We do know that we can generally represent color accurately by using three numbers, which correspond in some way to the three types of color cells in the eye. You can arrange all known colors into whatever kind of classification scheme you desire, but out of this infinity of schemes, only an infinitesimally small fraction of them display any kind of meaningful objective order: a good color-ordering scheme will be simple, and this simplicity will be expressed by having irreducibly three numbers to describe color. This means that you can arrange all colors into a three-dimentional shape, with the colors varying smoothly in some way in each direction. (There are color systems with four numbers, and some even go up to 10! These are used for printed output. Having more than three numbers for color is said to overspecified or redundant, and so there will usually be more than one way of specifying any unique color.)

There are many schemes used today to represent color, with each one typically using three numbers. The meaning of each of these numbers, however, changes drastically depending on the system used. The most common scheme is called the Red-Green-Blue, or RGB color space:

Color space example - RGB

This is the kind of color space used in cameras, and this is also used when editing photos.  We have three numbers, one each for the values of Red, Green, and Blue, and these numbers (for 8 bit files) go from 0 to 255. The beauty of this system is that when you continuously vary any one of the RGB colors, the tones you see vary in a natural manner — you typically don't get strange discontinuities in the color you see.

In this example, each slice of the image above has the named color go from 0 at the bottom, to 255 at the top, with the other color values being zero. A mix of numbers gives you different colors.

If all three values are zero, the result is black; if all three numbers are 255, then it is white: whenever all three values are the same, we get no color at all, but varying shades from black through gray to white.  This is very useful in Photoshop: if we want to white balance an image, we just have to identify places that ought to be white, gray, and black, and then apply curves to force the three numbers to have equal values in each area.

A bigger number means a brighter pure color. Now, here is the big limit to the RGB color space: what specific color is equal to 255?  As it turns out, that choice limits the gamut, or range of colors that can be represented by RGB. And so, we have many RGB color spaces, including the common sRGB color space used here, as well as AdobeRGB, ProPhoto RGB, ColorMatch RGB, and so forth.  sRGB has the narrowest gamut of the bunch, while all the others can represent a wider range of colors.

Practical computer science considerations are why we are limited to 256 levels for each color: this is due to the binary arithmetic used by computers and also due to the formerly extreme cost of computer equipment. 256 levels per color gives us a good total number of colors, and is generally adequate for quality photography.  Much fewer numbers of colors will likely introduce banding in the final image. But it is for this reason that sRGB is a decent color space to use, even though it can't represent the full range of colors: wide gamut color spaces may introduce banding because they might still use only 8 bits per color, and so the colors are spaced further apart.

When using Photoshop, I recommend using 16 bit mode, especially if you are going to do some extreme edits to your images. This reduces the possibility of banding.  However, you still have to reduce your final image to 8 bits per color if you want to display photos for the web. Also, be aware that many web browsers can only view sRGB images accurately: other color spaces will look bad.

Another consideration with RGB is how perceived brightness varies as the values go from 0 to 255. The simplistic idea that 200 will be twice as bright as 100 doesn't work well — for the human eye, twice as much light doesn't look twice as bright, rather it looks only a bit brighter. This phenomenon lets us see over vast ranges of brightness, and so the RGB scheme accounts for this by using gamma correction, which I'll go over in the future. Gamma correction assigns the RGB numbers in a way that appear a bit more more perceptually uniform.

RGB is the most common color space used, but that does not mean that it is the best for all purposes. When using curves, all three colors have to be modified at the same time, otherwise you will get color shifts. Also, how Photoshop determines the brightness of a particular color may not accurately reflect how the human eye sees it.

Photoshop is a bewildering piece of software, with a tremendous number of options. But there really are only a few key concepts that must be understood and mastered. I think the color channel system is essential. Each of the three numbers discussed earlier is broken off into its own channel: each channel is a black and white image made up of only one of the three numbers. Ideally, when you see a color image you should be able to imagine what each of the channels look like; also, if you are given a channel, you ought to be able to determine which color it goes with. For example, here are the RGB channels of the image above:

Color space example - RGB - channels

Is this what you imagined? For the red channel, we have no Green or Blue data, and so they are black in the places of the image that are green and blue. A value of 0 is black, and so 255 in the red channel will give you the brightest pure red. Just by looking at the Red channel, you ought to be able to determine that the only color you see on the left is red. Now, this is pretty straightforward for pure colors, but when we have other colors, it gets a bit more complicated.

Color space example - RGB - Red-Green only

Here we show only the red and green color channels, mixed together in various proportions. Can you imagine what the color channels look like? The blue channel is completely black (except for the white text). The red channel goes uniformly from 0 on the left to 255 on the extreme right, and likewise the green channel goes from 0 on the bottom to 255 on the top.

At the extreme bottom of the image, both green and blue are 0, and so we see pure red tones going from black to bright red. Likewise, along the left side of the image, we have pure green tones.

The upper right hand corner of the image has both red and green at 255, and blue at 0: this is pure, bright yellow. Along the right edge we see orange, which is a mixture of yellow and red, or rather, bright red with some green and no blue. The top edge shows lime green, a mixture of yellow and green, or pure green and some red and no blue.

The diagonal line from black to yellow shows equal portions of red and green. You may notice how very little of this region looks particularly yellow but instead is kind of a muddy color. Actually, the color brown is in reality a dim yellow or orange color, which looks muddy merely because of bright surrounding colors.  If you take a brown object, put it on a very black background, and brightly illuminate it, it will likely look nicely yellow or orange, and not brown at all.

Color space example - RGB - Green-Blue only

Here we show only green and blue, and the red channel is black.

The upper right hand corner of this image is cyan, which has 0 red, while both blue and green are at 255. These colors are very significant: they are the opponent colors of whatever channel is black. Ideally, those colors would be opposite from each other on a color wheel. So we see that cyan is the anti-red: there is no cyanish-red color possible, rather mixing them together on the computer only gives you gray.  Here are the important opponent colors:

Blue — Yellow
Red — Cyan
Green — Magenta

Whenever you see a bright saturated yellow, you will know that the blue channel there is black, and likewise for the other opponents.

Color space example - RGB - Red-Blue only

Red and blue gives magenta. Magenta is the anti-green.

Isaac Newton's color theory is very deficient because it cannot account for magenta colors; however, even this RGB system is deficient because it cannot give us a pure violet — a color that is ultra-blue, with no red it it whatsoever. But because of how we see, some tones of magenta appear violet to our eyes. Yes, color vision is complicated.

These illustrations show pure colors. If we were to include non-zero values for all three colors, we won't get any new colors, but only grayer and lighter tones of these existing pure colors. Having three RGB colors reduces saturation. Just by looking at the RGB numbers, you ought to be able to tell how saturated a color is; and if all three RGB numbers are equal, then you know you will have a completely unsaturated color: white, black, or shade of gray.

You don't need to see color in order to accurately analyze and color-correct an image in Photoshop. There is much ado made of having a calibrated monitor, and while that is good and useful, it is not absolutely essential. It is better to color-calibrate your images, because your eyes can fool you, especially when you are tired, and also no monitor calibration is perfect.  Just remember these rules:

All RGB numbers the same: gray
All RGB numbers high: white
All RGB number low: black
R high, others low: red
G high, others low: green
B high, others low: blue
R and G high, B low: yellow
R and B high, G low: magenta
G and B high, R low: cyan
Any one or two of RGB high; the others medium and equal: light unsaturated color or pastel
Any one or two RGB low; the others medium: unsaturated dark color.
R high, G medium, B low: orange
R high, B medium, G low: rose
G high, R medium, B low: lime
G high, B medium, R low: sea green
B high, R medium, G low: purple
B high, G medium, R low: sky blue

Suppose you take a photo with a ordinary clear blue midday sky.  Are the RGB numbers such that B is greater than G, and G is greater than R? If not, is it your artistic intent to make the sky look purple, or some other color than sky blue? If not, and if you intend to share your photos with others, especially on the Internet, then be sure your colors are right. If an objectively purple sky looks like a normal sky blue on your computer monitor, then you need to calibrate your monitor.

Remember, color calibrate your images before you calibrate your monitor!

If you are confident that you understand RGB, then take An RGB Quiz.
For an overview of the CMYK color system: Color Spaces, Part 2: CMYK and Part Two of "Color Spaces, Part 2: CMYK" as well as A CMYK Quiz.
See also Color Spaces, Part 3: HSB and HSL and Color Spaces, Part 4: Lab.

Monday, August 2, 2010

Baroque Image Processing

THE MORE I STUDY photography, the more I am convinced that photographers can learn from the older art forms.

Oil painting, "St. Paul", by El Greco (Domenikos Theotokopoulos), 1598-1600, at the Saint Louis Art Museum, in Saint Louis, Missouri, USA

This is a painting of Saint Paul by Domenikos Theotokopoulos ‘El Greco’, found at the Saint Louis Art Museum.

Traditional painting is inherently a low-contrast medium — a similar plight found by photographers in their medium. In order to produce an acceptable image with a limited range of contrast, painters would use contrasting color and tones, and outlines to visually divide areas in their paintings.  Here we can see halos of bright and dark paint along outlines, a technique similar to sharpening found in photography.

The folds of Paul's garments have strong contrast applied, and the great difference in brightness is used to good effect to imply three-dimentionality. This is similar to local contrast enhancement, a photographic post-processing technique similar to sharpening. By exaggerating the contrast in local areas of a photo, we can bring out detail in a way that looks plausible; this effect can be strongly applied, as is found in some High Dynamic Range tone-mapping techniques, or as we seen in this painting.

Sunday, August 1, 2010

Unsharp

I WAS DISTRACTED. My mind was wandering, and I found myself distracted by a flickering candle flame. It caught my eye — for it looked funny. The flame was about forty or so feet away, it was tiny to my eye, but I noticed a strange effect. The room was bright, and the flame was brighter still, but surrounding the flame, very distinct, was a black halo. That was very odd.  Distracted even more, I looked more carefully. Yes, I saw a thin black halo. No doubt about it.

Have you ever hit ‘pause’ on a DVD or video tape, and have you noticed how bad the image on your screen looks? Really, even decent quality video looks rather poor in image quality when still. It looks fuzzy. Beginner photographers can take better still images than even big-budget Hollywood filmmakers.

But Hollywood doesn't normally do fantastic image quality because it doesn't have to. This is due to a phenomenon called motion sharpening. Moving images look sharper that static ones. Once a video is playing, perceived image quality goes up tremendously. The same thing occurs when we look at moving objects around us.

This seems rather paradoxical, when you consider that the human eye has a latency which is roughly equivalent to a camera shutter speed of not much more than 1/10th of a second. We would expect moving things to look blurry. But the visual mechanism of motion sharpening makes up a bit for this slow “shutter speed.” Or perhaps our eyes have motion sharpening because of this inherent latency.

This isn't a well-understood process.  In fact, if you do a Google search of motion sharpening, all the top articles listed are fairly recent scientific peer-reviewed articles, hardly suitable for the layman. It is apparent that this field of study is fairly recent and not settled. Even though we don't understand this, it is a fact that the human eye adds the impression of sharpness to moving objects. Very likely this is what was happening when I was looking at the candle flame: the black halo around the flame was a sharpening artifact of my eyes, which made the flame more visually prominent, more sharp.

But if we look at an object that isn't moving, then we can expect that it will not be sharp. That is very bad news for photographers. Because we produce static images, we don't get the great sharpening advantage found by cinematographers or videographers, or even the advantage of what we see in real life, when things are moving around us. We are stuck with the job of producing relatively small images, which will be inherently soft — and not sharp — in visual quality.

An image without any contrast will be all one uniform tone, and so contrast is by definition what makes a photographic image. No contrast, no image. Sharpness is an example of contrast on a local scale within an image: lots of contrast near edges make them look sharp.

There are many sharpness woes for the digital photographer related to lack of contrast. I mentioned the static quality of photographs, and here are others:
  • The restricted contrast range of printed images. For black and white photography, you might have a 100:1 contrast range for even nice glossy prints.  Compare this to the enormous contrast range found out in the real world. Ordinary computer monitors also have a rather limited contrast range.
  • The limited degrees of contrast that can be mathematically represented by JPEG, the most common image format. With only 8 bits per color channel, you really can't subdivide the range of contrasts too much and you always risk banding in the final image.
  • Small image sensors typically produce inferior images, often due to the poor resolving power of the tiny lenses found in those cameras.  Rule number one for getting sharper images is using a larger sensor. But if you have too large of a sensor, you may have depth-of-field problems; stopping down the aperture to get decent range of focus may lead to diffraction, which introduces softness. 
  • You can't get enough sharpness if you don't have enough megapixels — a low megapixel camera can only be enlarged so much before you no longer see crisp detail.
  • You can't get enough sharpness if you have too many megapixels for the size of your sensor. First, your lens may not resolve sharply enough to actually use those pixels effectively; and second, tiny pixels produce noise. Lack of sharpness from inferior cameras is often evident even when a small image is presented on a computer screen.
  • Aggressive noise reduction found in some consumer grade digital cameras typically soften the image by decreasing detail in the image.
  • The ‘grain structure’ of digital photographs is markedly different from what we find in film. Pixels are typically square in shape, while film grain is rather pointy. The sharp edges of film grain can give a photograph the impression of overall sharpness, and this is lacking in digital technology.
  • Many types of image manipulation introduce softness, in particular image rotation, lens distortion correction, and any type of shear and perspective correction. This is ultimately a mathematical problem, and there are improved techniques that can partially correct for this.
  • Downsizing an image will tend to make it look soft. There are many algorithms for recalculating an image upon resize, and some do a better job than others, while others produce an artificial oversharpening. The algorithms found in Photoshop CS5 are rather limited.
  • Digital cameras have an anti-alias filter which intentionally adds softness to an image in order to avoid a specific kind of digital artifact. Pro-level cameras typically have a weaker filter than inexpensive consumer cameras, and medium format sensors have none. More megapixels help reduce this problem, but this may lead to more noise.
  • Unless you use short shutter speeds, or have a very sturdy tripod, images will likely be blurred — less sharp — due to camera motion. This kind of blur will ruin the images of even the highest quality cameras and optics, and is only partially correctable by anti-vibration technology.
Photographers have the problem of producing an image that looks sharp, in a medium that is inherently low-contrast — unsharp.

Would a relentless purist image, taken with superb optics, high-end sensor, and impeccable shooting technique be sharp without any artificial processing?  Sadly, the answer is likely NO; better, but perhaps still a bit soft, or at least open to improvement. As my initial experience with the candle flame shows, there is a sort of sharpening that occurs in the eye around moving objects, and pure digital images lack this kind of sharpening.

As it happens, digital cameras add artificial sharpening to images. They have to, otherwise their images would look soft. Better digital cameras let you adjust the amount of artificial sharpening, or turn it off altogether if you want to do your own sharpening during post-processing.

Sharpening is just one end of a wide range of techniques for adjusting local contrast in an image. Sharpening adjusts the contrast of edges, while closely related techniques adjust the contrast over larger parts of the image, like the shadows. Sharpening is a fine art, with many subtleties, and as mentioned, the natural mechanism is not well understood.

So I will whet your appetite with the most basic sharpening tool in Photoshop, Unsharp Mask, which gives us a measure of control over the sharpening process, and which can be used as a basis for more subtle and powerful techniques. That a sharpening tool is called Unsharp Mask is curious, but that will have to wait for another day. Let's just say that blurriness can lead to sharpness.

The problem with technology in generally is that we are often presented with a tool, yet with no real knowledge on how to use it; Unsharp Mask is no exception.

Here is an unremarkable photo, taken with a low-quality digital camera with no in-camera sharpening applied, and reduced in size using Photoshop's Bicubic algorithm, which is known to soften images:

DSCF6682 - unsharpened

I open Unsharp Mask, and am presented with three parameters:

Unsharp Mask 1


Now what? Too often, Photoshops' own documentation just lists features, and so do many Photoshop books.  These usually don't say how a tool ought to be used. Too many beginners seek formulae instead of understanding, and ask “what settings should I use?” rather than “how and when should I use this?”

OK, I am only interested in final sharpening, which should be done after resizing your image to its final size. As I mentioned, there are lots of sharpening-like methods we can do to increase local contrast, but here I am interested in making the smallest edges more prominent: this is the kind of sharpening done in-camera, and is the roughly the kind of sharpening done by the eye around moving objects.

There are three parameters here:
  • Amount: how much sharpening is applied.  0% is no sharpening at all, 500% is lots.
  • Radius: the distance over which sharpening is applied. This can vary from fine edges to broad areas.
  • Threshold: this limits the effect to only more prominent edges, and is used to prevent enhancing noise.
First, set the parameters to these values:  Amount = 500%, Radius = 5, and Threshold = 0.  We are going to search for noise, and make sure that it does not get enhanced. Normally, noise lives in the shadows, so I zoom into a dark part of the image:

Unsharp Mask 2

The noise is enhanced, and we need to reduce this problem. Raise the Threshold slider until the noise is not sharpened all that much:

Unsharp Mask 3

We have a trade-off here. If we don't want to sharpen any noise whatsoever, then we will do no sharpening. But if we have to set the Threshold slider above, say, 25, then the image is likely too noisy to sharpen. It is a poor image and needs other work before sharpening. Here I got rid of a lot of the noise, but not all of it.

Ok, now click on a part of your image that has good, in-focus detail; this will sharpen the best. I usually zoom in to 200% on Unsharp Mask's preview. Move the slider to a Radius of 0.1 and move it slowly higher; keep an eye on the edges.

There will be a point where the detail will visually ‘pop’; this is the point where Unsharp Mask overcomes the inherent digital softness of the image, and it will likely vary between images. This is a step, which for best work, ought to be done on an image-by-image basis. For me it is a Radius of 0.3:

Unsharp Mask 4

Now reduce the Amount until the image still looks sharp, but does not have obvious artifacts. The sharpness should be almost unconscious.

DSCF6682 - sharpened

This was sharpened to 423% and may be a bit over done, but this is representative of the kind of crude in-camera sharpening done by many inexpensive compact cameras. This method does increase the sharpness of edges, making them more distinct. This isn't great, and could be better, but it is a start.