Thursday, September 15, 2011

White Balance, Part 2: The Gray World Assumption and the Retinex Theory

WHITE BALANCE is one of the most important functions of digital color photography. Understanding a little bit of theory about this function could improve your photography.

Very many beginning photographers (and I was certainly one of them) are quite disappointed with the quality of their images. Although they may find it hard to put into words just what precisely is wrong with their images, bad color or a color cast may be a significant problem. When I learned about white balance and how to correct for it, I immediately thought that my photos looked much better.



Bad versus better white balance, among other things. Saint Vincent de Paul Chapel, in Shrewsbury, Missouri.

Clearly, the color of light is often variable, and the color my camera captures is usually somewhat different from what I see in real life. However, if I am careful to set the white balance, then typically my colors look much better under most circumstances.

There are some principles that we ought to keep in mind:
  • Our eyes do white balancing naturally. This leads to color constancy, where particular shades of color appear to be subjectively similar under a wide variety of objectively different lighting conditions.
  • White balance in photography corrects for extreme changes in the color of light; it is not a slight adjustment.
  • For the best results, we ought to do white balancing early in the photographic process.
  • We cannot rely on the camera or software automatic white balance function to give good results.

Friday, August 19, 2011

Anniversary of the Daguerrotype

ON AUGUST 19th 1839, the government of France released the patent on the Daguerrotype to the world, which made photography commonplace.

The promise of photography had been around for decades: Joseph Nicéphore Niépce had been working on his heliograph process since 1793. His problem was that his photographs quickly faded, and his oldest surviving images date from about 1825 or 1826. Starting in 1829, Niépce partnered with the prominent painter Louis-Jacques-Mandé Daguerre to further develop the heliograph process.

Daguerre and Niépce worked on the physautotype, a process where lavender oil dissolved in alcohol was applied to a silver plate to produce an image. This process required that the plate be exposed in a camera obscura for many hours. After Niépce's death in 1833, Daguerre discovered that exposing a silver plate to iodine vapors before exposure, and then mercury vapor afterwards, could produce a plate far more sensitive to light. Daguerre patented his process in 1839, and then gave his patent to the French government in exchange for a pension for himself and Niépce's heirs.

There was a boom in professional photography. By the 1850s, photography studios could be found in nearly every major city.

Monday, August 1, 2011

1 Bit Depth Cameras

PLEASE EXAMINE these two photos:

Flower-8 bit-reduced

Flower-1 bit-reduced

Not too much difference.  The second photo has perhaps slightly greater contrast, saturation, and sharpness.

Now both these images came from the same RAW file, but had different processing; I reduced these images to this size using Photoshop's Bicubic algorithm.

Now let's zoom far into a small part of the original images:

zoomed

The second image has one bit per color channel!  Each of the red, green, and blue color channels is either fully on or off, and so we have only 8 possible colors per pixel versus millions of possible colors in the top image. But when we reduced the image in size, these pixels were averaged, and so appear normal in the final image. By averaging, we can obtain every possible color in the sRGB gamut.

Lousy, horrible image quality, when we pixel-peep at 100% resolution; but it looks just fine at the resolution shown on the screen.

But we really don't have to do pixel averaging to get a plausible image:

Union Station in Saint Louis - 1 bit depth image

The pixels on this image are black and white only — no shades of gray. This image is interesting, but it has poor image quality; but if we had more and smaller pixels, an image like this would appear to the eye to be a continuous grayscale of high quality.

The notorious megapixel wars of a few years ago had new models of cameras coming out with ever higher pixel densities, at the expense of higher noise. When I got my Nikon D40 back in 2008, I specifically chose that model because it had the best balance between noise and pixel density. Since I was going to produce full-resolution images for the book Catholic St. Louis: A Pictorial History, I needed a minimum number of high-quality pixels for full-page images. Now I could have used a higher pixel density camera, but at that time I had problems with image downsizing, which harms sharpness.

The problem with high megapixel, small sensor cameras is noise; but noise is not a problem if you don't look too closely: and clever image manipulation can make this noise invisible or unobjectionable in the final image. Let's not forget that the single best predictor of image quality is sensor size. You can get a decent small image with a small sensor, but a large sensor will deliver high image quality with both small and large images.

What this little experiment tells us is that we don't need high quality pixels to get a high quality final image, if we have enough pixels.

Suppose some manufacturer could cram 250 megapixels into a typical ASP-C sized sensor as found in consumer grade DSLR cameras. If you zoom into your image at 100% resolution, the image might appear to be only noise, but by clever processing you could produce excellent large images with superb detail.

We can learn a few lessons from old film photography. The crystals of silver halide embedded in film change chemically when exposed to light. Please be aware that light, when examined closely, appears to be made up of little discrete chunks called photons. Whenever a number of photons would hit a piece of silver halide, no matter how large or small a crystal, the crystal would change. And so, large crystals are more sensitive to light than smaller crystals, since roughly the same number of photons would likely change either size crystal. The crystals that absorbed photons would then remain in the negative, and would appear black, while the crystals that did not absorb photons would be washed away during developing, and so only the transparent film remain.

So in a certain sense, digital photography is more analog than film photography, and film is more digital than digital sensors.  A film grain is either on or off, with no intermediate steps, no shades of gray. In developed film there is either a grain at any given part of a negative, or there isn't: it is all black or white. Only when we look at the negative from a distance can we perceive an image.

Film grain has many advantages. Because the grains have random shapes, we do not see aliasing in film images — we don't see digital jaggies or interference patterns. By mixing various sizes of grains, we can expand the dynamic range of film: some grains will be more likely than others to be exposed, and so we can get both good shadow and highlight detail, as well as a gradual fall-off in highlights, instead of an abrupt cutoff in highlights as we see with digital cameras (Some Fuji digital cameras had two sizes of sensors to avoid this a bit). Film grain can also add perceived texture as well as sharpness.

Digital photography, following the long example of film technology, could utilize very large numbers of tiny pixel sensors of varying sizes and shapes, and these sensors would register only on or off signals: they would be 1 bit sensors, just like film grain. Although pixel peeping on such an image would be painful, we should expect to obtain superior final images, with much higher dynamic range, good fall-off on highlights, and nice texture and sharpness without digital artifacts. We also would have better control over digital noise, particularly in the shadows.

One interesting advantage to having super high pixel densities is that camera manufacturers could include sensors of various color sensitivities, greatly expanding the color gamut of the sensor, as well as provide far more accurate color rendition. These extra color sensors could emulate the Purkinje effect, and be able to accurately capture an image that corresponds to how humans see in dim lighting, particularly at dusk. Some sensors could be sensitive to infrared, and others to ultraviolet. We have so many pixels in our camera that it wouldn't be much of a waste to assign a certain number of them for odd uses: it would hardly cause a degradation for most images. Various sizes of pixels could be scattered across the sensor, giving better dynamic range; random shapes and sizes could produce images less prone to aliasing, as well as providing more sharpness.

Sensor design would be challenging, for various trade-offs will need to be made: what would be a good balanced design? Blue sensitivity is poor in the standard Bayer design, and red sensors could be boosted in number also. Why can't we also include a number of panchromatic sensors as well, instead of relying mainly on green for luminance? What percentage of the sensor area should be dedicated to big sensors, how many tiny pixels should be included? Can small pixels be superimposed upon big pixels? If varying shapes of pixels are used, what shapes are best; pointy or round? This design offers great potential. Manufacturers could even incorporate Foveon-style sensors, where multiple colors are sensed at the same location. They could even get very clever, by changing the size of the sensors according to depth.

RAW conversion for such a sensor would be difficult — or rather interesting — and would likely require a much faster on-board computer in the camera. But for a hypothetical 250 megapixel camera, we would have precisely one bit per pixel, and so the RAW file size would be only about 31 megabytes in size before compression: not terribly much larger than what we have today. JPEGs produced by this kind of camera would not be full resolution, but then we don't want full resolution, we need to have some sort of averaging of the pixels. But even a lightly processed TIFF file would produce a superior image; up close, we would perceive something that would look like photographic grain, which is much more organic than digital pixels.

This kind of camera would give us unprecedented control over the RAW conversion process. You want an infrared image? You got it. You want ultraviolet? Easy. You want to trade off color accuracy for dynamic range? You want to bring up detail in both the highlights and shadows? A one-bit depth camera can be very useful.

Thursday, July 7, 2011

Coming Soon

IMAGINE A light source, which can automatically match the color of ambient light.

So many times I've taken interior photos, with the room illuminated by tungsten lighting; however, some light comes through the windows, but that looks strongly blue and so harms the photo. For my best work, I adjust the color of the window lighting and the artificial lighting separately in Photoshop, but this is time-consuming and error-prone. Big-budget cinematographers will put colored gels over the windows to get the light colors to match, or they will put gels over their lights. But the use of gels has the unfortunate side-effect of decreasing the light intensity, requiring even brighter and hotter light sources, much to the dismay of the actors.

Rift Labs is developing a three-color lighting panel which has variable color temperature. Using low-power, three-color light-emitting diodes, their forthcoming light panels will automatically be able to match any lighting situation. Or, any color of light can be dialed-in, and the brightness of the lighting does not change.

So photographers and cinematographers can have a portable, battery-operated, low-cost lighting system which can quickly and conveniently produce the color of lighting needed. A good use of this would likely be for fill-in lighting, an augment to ambient lighting. Portable, battery-operated white-light LED panels have appeared in the last couple of years, causing much excitement, but Rift is taking this to the next level.

The organization is making these lighting units open-source, and provide the circuit diagrams and controller software free of charge; if their concept proves usable, we ought to see many similar designs produced at low cost in the near future.


I noticed that they are having trouble finding the correct method of producing a uniform illuminance under a change of color temperature. This is likely to be problematic for them, since the sensitivity of digital cameras to various color temperature conditions is variable across manufacturers and models of cameras.  See here. They may need to adapt their system to include color calibration data specific to particular kinds of cameras. Likely this will merely require a custom color transfer matrix — nine numbers — that will provide closer mapping between what the camera sees and what the light source delivers. This color matrix could either be encoded as a camera model database in the device firmware, or the user could type in the numbers if they know them. A more clever method could be a built-in algorithm for color calibrating the camera: this little feature could be a strong selling point.

I also wonder about the color quality produced by this kind of unit. Since it uses only three colors — red, green, and blue — it may not operate equally well under all color gamuts used by digital cameras. Please recall that it is impossible to mix all possible colors from only three primary colors.  However, if they concentrate on getting sRGB right, then this unit ought to operate well for 99% of uses. But there will still be metamerism problems: colors that look identical to the human eye will look different to the camera, and this kind of three-color lighting will make metamerism failure even more prominent. They may find they get better performance if they also include some other colors in their LED array to provide a more uniform spectrum.

This kind of lighting could be of great benefit for those who shoot RAW. Digital cameras have a fixed white balance: this raw data is processed to produce images correctly balanced according to the color of the light. However, lots of the RAW data is thrown away during this processing, which leads to increased digital noise, particularly in the red and blue channels. The Rift Labs product can be adjusted to produce a magenta light which will accurately produce an accurate RAW light balance: no data is thrown away, and the noise level is reduced to its practical minimum. This is likely only of interest to specialists, but it does show how useful this device can be.

UPDATE: Click here to read an article on color rendition under LED lamps. You may expect color shifts with using these kinds of products.

Friday, July 1, 2011

Contrast, part 1: Black and White

A FRIEND ASKS, “What is contrast?”

Simply, contrast in photography is what differentiates one thing from another because of differences in tone. A contrasty image will have lots of black and white tones, while a low-contrast image will have lots of medium gray.

The English word ‘contrast’ comes from the Latin contrastare, meaning ‘stand against’, and so in a contrasty image, some elements will strongly stand against others, instead of blending together.

Here is a more-or-less visually uniform grayscale image that I'll be using as the basis for examples:

Grayscale with noise

It goes from black on the left, to white on the right.  I threw in a little bit of noise to illustrate my examples better. I used this contrived image instead of a real photograph in order to more accurately show what is going on. Please don't get too bored with this repetition.

Here is this grayscale's histogram in Photoshop:

Grayscale with noise - histogram

The grayscale illustrate how many pixels are in each range of tone; with black pixels on the far left, and white pixels on the far right. The noise adds lots of jitter to this histogram, but please note that it is otherwise fairly uniform going across; on average, there is just as much black as there is white, and just as much middle gray as either of those.

Photographically, we can use the word contrast in various ways. Global contrast — which is what we are mainly concerned with here — tells us how the total range of tones are divided up in an image; how much strong black and strong white are found in an image?  Since our example image is uniform, we can say this has neutral global contrast.

Here I use the Brightness/Contrast tool in Photoshop:

Grayscale with high contrast

I made this image with this Photoshop setting:

Grayscale with high contrast - histogram

Setting the slider to 100 contrast gives us simultaneously more dark and more light tones, at the expense of midtones. Take a look at the histogram: we have more pixels at the far left and right.

Setting the slider to -50 gives us low contrast:

Grayscale with low contrast

Now notice how we have more midtones, at the expense of fewer dark and light pixels. The histogram shows the pixels more clumped together in the middle:

Grayscale with low contrast - histogram

Here are all three together:

Grayscale with contrast adjustments

High contrast on top; low contrast on bottom.

Now I don't normally use the Brightness/Contrast tool, since I can get more control over the final results when I use the Curves tool.

Here I apply Curves to make the image appear to be basically the same as the Brightness/Contrast 100% setting:

Grayscale with high curves contrast

Note that the histogram looks pretty much the same. But also notice that the curve is a bit complex:

Grayscale with high curves contrast - histogram

Here is how we interpret the curves:
  • The bottom axis shows us the tones of our original image; while the vertical axis shows us which tones are changed by Curves.
  • Note there is a diagonal line going from the lower left to upper right; any time the curve touches this line, that means that the corresponding tones are not changed. In our example here, pure white, black, and middle gray are not changed. Whatever is white, black, or middle gray in the original image will remain unchanged in the final image.
  • Whenever the curve drops below the diagonal line, that means the tones are brightened. Whenever the curve raises above the line, those tones are darkened. In this example, the light tones between middle gray and white become brighter, while the dark tones between middle gray and black become darker. The image has greater global contrast, because we simultaneously get more darks and more brights.
  • In this curve, 70% white in the original image becomes 80% white in the final image; likewise 30% white (= 70% black) becomes 20% white (or 80% black). 0%, 50%, and 100% remain unchanged.
The Curves box shown here is not quite the same as found in Photoshop's default settings.  Here are my custom settings:

Curve Display Options

Now let us define a new term, ‘differential contrast’. Take a look at the curve above: notice how it is steeper at the midpoint, and less steep at the endpoints of black and white? If you were climbing a hill with that slope, you would likely have the most difficulty in the midsection, where the curve is steeper.  What this means is that there is more differentiation in the midtones; visually they appear more distinct from each other. Also note that there is less differentiation between the various dark tones and the light tones.

Whenever we get more differential contrast in one range of tones, inevitably we will get less differential contrast in other range of tones. As a photographer with Photoshop, you have control over adjusting which range of tones get the greatest differential contrast. You ought to consider adding differential contrast to those most important tones in your image, by making sure that the steepest part of your curve extends over that range of tones. But this can only be done by sacrificing other ranges of tones.

From what we can see with the curve above, it is apparent that the standard Photoshop Contrast tool adds differential contrast to midtones, at the expense of both shadows and highlights.

If we adjust the curve so that the line is steepest at the endpoints, and less steep in the middle, then we will get a low contrast image; it will have greater differential contrast in the shadows and highlights at the expense of the midtones. The overall global contrast will be less because we will have less dark and less light, with a lot more middle gray.

From our little experiments here, we can see that the Photoshop Contrast tool is a bit like Curves, but only where the endpoints and middle are fixed. We don't have to keep our endpoints fixed in Curves.  For example, I can get much lower contrast in Curves:

Grayscale with low linear curves contrast

This image does not go from pure black to pure white, rather, its range is significantly reduced.

Grayscale with low linear curves contrast - histogram

Note that the histogram does not go all the way to the edges; indeed we are using only half of the dynamic range available. In our curve, 100% white is transformed to only 75% white, and likewise for black. Our total global contrast has been reduced greatly. But unlike the curved curve shown above, the differential contrast between tones is the same across all tones, since our curve is straight here.

If we make the curve completely horizontal, we lose all contrast:

Grayscale with no contrast

Grayscale with no contrast - histogram

Our histogram is now simply a spike at middle gray. Our image has no contrast whatsoever.

If we make the curve vertical, we get maximal contrast:

Grayscale with maximum curves contrast

Please note that I added some noise in the image to simulate texture.

Grayscale with maximum curves contrast - histogram

Actually Photoshop does not let us make a true vertical line, but this is pretty close. On the histogram, we have spikes at pure black on the left and pure white on the right.  We have lots of differential contrast at the middle gray, with none for darker and lighter tones.

Take a look at the data found in the Histogram boxes in the images above. Note that in all cases, the Mean value is close to 127.5, which is medium gray. We did not change the overall brightness of the image with our adjustments. The next value, ‘Std Dev’ (or Standard Deviation) is a measure of how much the pixel values deviate from the mean. A large standard deviation is high contrast, while a low standard deviation indicates low contrast.

One of the great powers of Curves is that we can increase or decrease differential contrast in whatever range of tones we desire. In our examples above, the middle point is always fixed, and so differential contrast is adjusted only for the midtones. With Curves, we can adjust the contrast in the highlights:

Grayscale with contrast in highlights

Note that here we have greater distinction in the brightest tones in the image (you can see lots of my added noise there), and we have essentially created a low-key image.

Grayscale with contrast in highlights - histogram

But this distinction in the highlights comes at the expense of losing lots of our shadow detail. The tall spike at the leftmost part of the histogram unfortunately does not give us a good impression of how much of the image is lost in black without significant texture: roughly 40% of the pixels are pure black.

We can also increase visual detail in the shadows at the expense of the highlights:

Grayscale with contrast in shadows

We now have a high-key image.

Grayscale with contrast in shadows - histogram

Here our curve and histogram are reverse of what we had before, and 40% of our highlight detail is lost as pure white.

OK, let's try these techniques with a real image. This is a low-contrast, dim, black and white image of a monument found in Sylvan Springs Park, in Saint Louis County, Missouri, USA.

Example original

Bleh.  Looks poor, and here is its histogram:

Example original - histogram

Most of the image's pixels are on the dark side of the histogram. Unless this is an exercise in conceptual art, most photo editors at magazines would reject this image: most would probably like to see a broad histogram, with significant contrast and a full range of tones from black to white.

Merely using the Contrast tool in Photoshop does not help:

Example with high contrast only

Example with high contrast only - histogram

However, boosting the brightness here would help a lot.

Instead, I will adjust the image using curves.  First I put in an initial curve, which will expand the range of the significant part of the image:

Example with linear curve - histogram

Straight line curves are equivalent to using the Levels tool in Photoshop.

Then I add a strong curve to the most significant part of the image, which I think are the tones around the carved lettering:

Example with strong curve - histogram

The steepest part of the curve, and therefore the greatest amount of differential contrast can now be found at the tones surrounding the text “1939”. I don't care to see texture in the darkest part of the grass or in the shadows between the rocks; I think that overexposing the patch to the left of  “Sylvan” is also acceptable.

Example with strong curve

I added some sharpening, and the photo is basically complete.

Sharpening is a kind of local contrast enhancement, which is a powerful technique for improving images; but that is for another day.

Adding contrast — and using curves — in a color image is far more problematic, since we can easily change the hues of our colors. That is also a topic for later.

Monday, June 20, 2011

Examples of Color Mixing

I PURCHASED ADOBE Photoshop CS3 a number of years ago for one and only one reason: color management.

I was the owner of a Minolta Dimage 7 camera, and was greatly disappointed in its photos. Naturally, I blamed the camera and had huge buyer's remorse. One of the many problems was that the camera took photos in a non-standard colorspace. According to the camera review linked above:
Looking over the D7's images I couldn't help but feel that certain colours seemed under-saturated (mostly greens and blues)...

At this stage it was clear to me that the DiMAGE 7 was shooting in its own colour space...

This is not documented in the DiMAGE 7 manual. I feel it should be made very clear to users, there's certainly a chance that the average user will simply load images directly from the camera using a card reader and never use the Minolta Image Viewer. These users may well end up disappointed by the D7's colour.

The average user won't know what colour space they're in, indeed most users don't even calibrated their monitors. However, at a consumer level, most of you will be viewing this web page and all the digital photographs you ever deal with in the sRGB colour space.
I admit that at the time I didn't know much about color spaces (and really I still don't). My Dimage images looked poor for various reasons, and the processing utility that came with the camera produced very dark, unacceptable images. Despite doing some research, I really didn't know how to correct for these problems, most notably the color space problem.

Then at Christmas 2006, I received a copy of Adobe Photoshop Elements. By that time I had already purchased a newer, somewhat inferior camera, but it produced great images right out of the box. But I tried using the Adobe Camera RAW software in Elements to process my old Dimage photos — and behold! — they looked great. The Adobe software knew all about the Dimage color space problem and correctly converted my images to the Web standard sRGB colorspace, and solved other problems too. By the next summer, I upgraded to Photoshop CS3 to gain access to the more advanced features in Adobe Camera RAW.


To the left is a typical JPEG image I got from the Dimage. On the right is an image I shot in RAW and processed with ACR.

So I was a new owner of Photoshop. But I didn't know how to use it much beyond the excellent RAW conversions. Many of the functions seemed to be useful for only producing odd special effects; although I didn't know it at the time, I was using a chain saw instead of a scalpel.


For example, I thought the Curves and the Channel Mixer functions were only used to produce special effects as seen here. Perhaps you can, but that is neither the intent of the tools nor is it their highest and best use.  In the bottom image, I randomly adjusted the sliders in Channel Mixer.

Thanks to Dan Margulis' excellent book, Professional Photoshop, Fifth Edition, I learned a few tricks on the right use of some of the Photoshop tools.  For example, Dan showed how to brighten green foliage using Channel Mixer:



Following are the adjustments:


Searching around the web, I see that most people use the channel mixer as a kind of mysterious saturation or desaturation tool. Above we see how it is used to brighten a color. It is often used as a black and white conversion tool: all you need to do is check the 'Monochrome' box and adjust the sliders until you get the contrast you desire in your conversion.

For a while I've been interested in the Purkinje effect, which describes the shift in colors we experience as light gets dimmer. I was prompted to do this in response the the poor quality of photos I took around dusk: how, I thought, could I reliably and repeatedly correct my photographs to look something like I remember seeing it? My earlier efforts at coming up with a Purkinje correction are here and here.


This correction is a two-step process. First I adjust the relative tonalities of the colors in the scene. When light gets darker, the eye becomes more sensitive to blue-green light, and simultaneously gets less sensitive to red colors. In particular, foliage has a strong red color component in daylight which makes them appear yellow-green; under dim lighting, foliage looks relatively darker. I also noticed that I had to adjust the white balance towards a sky blue color.

In the scene above, I distinctly recall the foliage being quite dark, while the fountain (seen in the lower right corner), the limestone edging on the sidewalk, and the columns appeared much brighter than the surrounding areas.  In a Luminosity layer, I used the channel mixer to both boost the brightness of the blue channel and to darken the red channel:


I could not just use this channel mixer indiscriminately across the image; the yellow light in the window in the tower was also darkened unrealistically. In this image, I applied the channel mixer with masking so that it did not change the brightest tones in the image.

I got these numbers in the channel mixer by comparing charts of light response of the dark adapted eye versus the sRGB primary color response to light. Measuring the response values across the color spectrum and doing some statistics, I was able to determine which mixture of color components best simulated the eye's night-adapted response.  Here we are getting very close to the intended use of the channel mixer.

The most precise use of the Channel Mixer is for converting between various RGB color spaces. Please consider how I started the article: my old Dimage camera had an odd color space, which if not handled properly, would produce disappointing images and poor color rendition.

Every digital camera has a native color space, and it isn't the Internet standard sRGB or Adobe RGB. Every brand of digital camera has a native color gamut that is whatever. The electronics within the camera do the conversion between the camera's native color space and sRGB; or, if you shoot in RAW, the software on your computer (like Adobe Camera RAW, Lightroom, or Apple Aperture) does it for you after the fact. Digital cameras are sensitive to the various colors in a manner which is quite unlike the human eye's response. Practically speaking, a digital camera is limited by cost, manufacturing technique, and long-term stability; while the human eye is precious beyond cost, has the most complicated manufacturing known, and repairs itself. Therefore it is unrealistic to expect that cameras will see color precisely as is seen by human eyes.

As it turns out, it is very difficult to get precise color capture capability on a digital device, and forget about trying to capture color precisely as the human eye sees it, especially with exceptionally pure colors. (Technically speaking, digital cameras do not meet the Luther-Ives Condition, which determines if a camera can capture colors accurately.) There are cameras that do have better color rendition than consumer or pro-level cameras but a) you can't afford them, b) you don't want to spend the time getting them to work right, c) these cameras only work in controlled laboratory conditions, and d) you won't be able to display your accurate colors on a computer monitor or print them on a printer. So we are looking for good enough colors.

So we take a digital camera that has a color space of whatever, and we use the computer to convert the images to a standard color space like sRGB.  Here is an example photo taken with my Nikon D40. I shot this X-Rite ColorChecker Passport in daylight using RAW capture. I set the white balance using the neutral card in the bottom photo.  Here I used Nikon View NX2 software to convert the RAW image to JPEG in the sRGB color space:


I held up the target in daylight coming through my office window, and compared it to this image on my screen.  The colors look pretty accurate. But this is not the image as the camera captures it. There is some significant processing going on to produce this final image.  Here is an approximation of how the camera really sees the target:


I used the free and excellent RAW Photo Processor for Mac OS X. I set the white balance to UniWB, set the gamma to 1.0, and saved the image as raw pixels without a color profile loaded.  By looking at this image we can see that the camera is very sensitive to green light, less sensitive to blue, and not very sensitive to red light. All cameras have a fixed, native white balance which does not correspond to any common lighting condition. Because digital cameras capture more than 8 bits per channel — usually in the range of 10 to 14 bits per channel — these extra bits are used to prevent banding artifacts when the software does this kind of processing.  For daylight, the camera must amplify the blue channel by about 50% and approximately doubles the signal in the red channel. Under incandescent lighting, the red and green channels are usually fine, but the blue channel must be boosted strongly, which typically causes lots of noise.

Let's do a white balance.  I used RAW Photo Processor to apply the white balance which I captured when I took the photo:


Cameras don't see light like humans do. In a camera, twice the light intensity generates twice the RAW signal; with humans, doubling the intensity of light makes a scene look only somewhat brighter. Likewise, halving the intensity of light only makes a thing look slightly darker. And so digital images are designed to provide extra sensitivity to the darker tones at the expense of brighter tones; this will allow us to more efficiently use our image data by allocating more data to the important midtones. To correct for this, we have to brighten the midtones in the camera's image, while keeping the very darkest and brightest tones unchanged.

Here I applied a brightness (or gamma) correction in RAW Photo Processor. This is not the precisely same brightness curve as is found in the sRGB standard, so the tonality of this image doesn't quite match the Nikon-processed image. But it is good enough for our purposes.


The first thing I notice is that the colors are disappointing. They look a bit flat and unsaturated compared to the first image. But this is actually a good thing. It tells me that my camera's native color space — whatever it is — is broader than the sRGB color standard. This flatness tells me that the colors could be potentially much brighter, if only I use a large enough color space, one larger than sRGB. In the camera native color space, the bright red color on our X-Rite target is merely mediocre.

To do this conversion from the camera native color space to sRGB in Photoshop, we imitate the processing used by the camera manufacturers by using Channel Mixer.

Suppose you take a given standard color, and take a photograph of it, being careful to do a good white balance and exposure. Good standard colors ought to produce a particular sRGB color value if exposed correctly; for example, a pure red the same color as the sRGB primary red color ought to give you R=255, G=0, B=0. But since your digital camera uses a different color system, it gives you another value, such as R=200, G=58, B=27. Your digital camera likely has a primary red color that is brighter, more saturated, and more pure than what the sRGB standard can describe.

So what we do is to boost the camera's red value somewhat, and then subtract out any green or blue that happens to be contaminating the red. So for any given Camera RAW value, we can get the equivalent sRGB values.

I got test data from DxOMark, a company that measures performance data for digital cameras and lenses. Here is an excerpt from the dataset:


Go to http://www.dxomark.com/index.php/Camera-Sensor/All-tested-sensors/Nikon/D40, click on Color Response, and click CIE-D50. This gives you daylight color data. They also provide CIE-A data, which models incandescent lighting.

Please note the White balance scales: this shows how much we should boost the various RAW color channels to get good white balance under D50 daylight conditions. Please note that D50 is much bluer than midday sunlight at mid-lattitudes, but is a good enough approximation for our use here.

To convert the RAW data to sRGB, we put the DxOMark Color matrix data above into the Channel Mixer:


Please note that due to rounding errors, the numbers in each Output Channel do not total to 100%. Undoubtably this will shift our white balance slightly.  Generally speaking, be sure that each channel mixer output channel totals to 100% to avoid a change in white balance. However, the final image looks pretty good:


The colors are fairly close to the Nikon-produced colors.

You can use the same sort of process to do your own camera calibrations under all kinds of lighting conditions. Please note that the DxOMark color matrix data assumes the use of something like the channel mixer to convert from the camera's native color space to sRGB. For example:

sRGB Red = (1.64 x Camera RAW Red) - (0.61 x Camera RAW Green) - (0.02 x Camera RAW Blue)

If you have a target with known sRGB (or other color space) values, you can convert an image to these colors by comparing the delivered colors with the known colors. I use Microsoft Excel to come up with estimates for the channel mixer values, using the Solver tool found in the Analysis ToolPak add-in. This is a rather complicated step, and requires some knowledge of statistics.

Please note that this mathematical transformation between color spaces is not exact, but is rather statistical in nature; the conversion matrix merely gives good color conversions on average. A severe channel mixer setting will also cause much more noise in your image.

Monday, June 13, 2011

"The False Photographer"

ON THE LIMITS of photography:
This weakness in civilisation is best expressed by saying that it cares more for science than for truth. It prides itself on its "methods" more than its results; it is satisfied with precision, discipline, good communications, rather than with the sense of reality. But there are precise falsehoods as well as precise facts. Discipline may only mean a hundred men making the same mistake at the same minute. And good communications may in practice be very like those evil communications which are said to corrupt good manners. Broadly, we have reached a “scientific age,” which wants to know whether the train is in the timetable, but not whether the train is in the station. I take one instance in our police inquiries that I happen to have come across: the case of photography.

Some years ago a poet of considerable genius tragically disappeared, and the authorities or the newspapers circulated a photograph of him, so that he might be identified. The photograph, as I remember it, depicted or suggested a handsome, haughty, and somewhat pallid man with his head thrown back, with long distinguished features, colourless thin hair and slight moustache, and though conveyed merely by the head and shoulders, a definite impression of height. If I had gone by that photograph I should have gone about looking for a long soldierly but listless man, with a profile rather like the Duke of Connaught's.

Only, as it happened, I knew the poet personally; I had seen him a great many times, and he had an appearance that nobody could possibly forget, if seen only once. He had the mark of those dark and passionate Westland Scotch, who before Burns and after have given many such dark eyes and dark emotions to the world. But in him the unmistakable strain, Gaelic or whatever it is, was accentuated almost to oddity; and he looked like some swarthy elf. He was small, with a big head and a crescent of coal-black hair round the back of a vast dome of baldness. Immediately under his eyes his cheekbones had so high a colour that they might have been painted scarlet; three black tufts, two on the upper lip and one under the lower, seemed to touch up the face with the fierce moustaches of Mephistopheles. His eyes had that "dancing madness" in them which Stevenson saw in the Gaelic eyes of Alan Breck; but he sometimes distorted the expression by screwing a monstrous monocle into one of them. A man more unmistakable would have been hard to find. You could have picked him out in any crowd—so long as you had not seen his photograph.

But in this scientific picture of him twenty causes, accidental and conventional, had combined to obliterate him altogether. The limits of photography forbade the strong and almost melodramatic colouring of cheek and eyebrow. The accident of the lighting took nearly all the darkness out of the hair and made him look almost like a fair man. The framing and limitation of the shoulders made him look like a big man; and the devastating bore of being photographed when you want to write poetry made him look like a lazy man. Holding his head back, as people do when they are being photographed (or shot), but as he certainly never held it normally, accidentally concealed the bald dome that dominated his slight figure. Here we have a clockwork picture, begun and finished by a button and a box of chemicals, from which every projecting feature has been more delicately and dexterously omitted than they could have been by the most namby-pamby flatterer, painting in the weakest water-colours, on the smoothest ivory.

I happen to possess a book of Mr. Max Beerbohm's caricatures, one of which depicts the unfortunate poet in question. To say it represents an utterly incredible hobgoblin is to express in faint and inadequate language the license of its sprawling lines. The authorities thought it strictly safe and scientific to circulate the poet's photograph. They would have clapped me in an asylum if I had asked them to circulate Max's caricature. But the caricature would have been far more likely to find the man.
— G.K. Chesterton, “The False Photographer”, from A Miscellany of Men.