Wednesday, June 6, 2007

How to selectively change parts of your image in photoshop

The ability to make complex and precise selections is required if one wants to differentially edit one's images. For example, if you have a photo of someone in the shade of a tree, but in front of a bright, sunlit landscape, the color cast on your subject will be quite different than that of the background. Making a global color adjustment could benefit one part of the image but hurt another.

Furthermore, making very precise selections allows you to combine differently edited versions of the same RAW image, or to combine a series of exposures that were bracketed for complex or high contrast lighting conditions.

Many have you have watched hours of your life trickling away as you struggled with the lasso, magnetic lasso, magic wand, and other selection tools. But can you really use these to select individual hairs or leaves?

Fortunately, for many images, the selection has already been made for you. It is merely incumbent upon you to extract them!

The principal we will employ in this tutorial is that of exploiting differences between different regions of a photo. This tutorial is geared towards those who use Adobe Photoshop, but it will certainly work in other programs. For those who use Photoshop Elements, I will provide some pointers that will allow you to perform similar techniques.

Now, we recognize an 'object' in a photo because it contrasts with its surroundings -- its color and lighting differ sufficiently from its surroundings that we recognize its shape. In order to select this object, we need to maximize these contrast relationships.

Here is a photo that I've recently taken of a baobab tree in Senegal. The tree is too dark, but if I adjust the curves or levels the sky becomes too bright. So I would like to perfectly select the tree so that I can modify the tree and the sky independently of one another. But believe me, there isn't time in my life to select the tree, complete with twigs and leaves, yet avoid selecting the little bits of sky, using Photoshop's selection tools.

To select the tree most easily and precisely, we need look at the Channels. In RGB images, there are three channels: Red, Green, and Blue. All are grayscale images, which, when combined, constitute a color image in the RGB color space. In the Red channel, objects that are very red appear light, objects very cyan (red's opposite) appear dark. In the Green channel green appears light and magenta appears dark. In the Blue channel blue appears light and yellow appears dark. Thus it is often predictable which channel will display the most contrast. Nonetheless, it is easy to go to the channels in Photoshop and see which one in which your subject is the most prominent.

There are other color spaces in Photoshop besides RGB. Lab color, for instance, uses three channels: Lightness, which contains all the tonal (light-dark) information in the picture, and two color channels. The a channel is a spectrum from green (negative) to magenta (positive), and the b channel is a spectrum from blue (negative) to yellow (positive). Neutral tones (shades of white and gray) occupy the midline of the a and b channel.

The CMYK channel is often used for printing, as it mimics the inks used on many printers: cyan, magenta, yellow, and black. It is a small color space, and generally not a good space to use for image editing. It can, however, be a good source of grayscale versions of your photo.

Below you can see all the various grayscale images that exist in the Photoshop color spaces. Once a useful channel is identified, you can make a duplicate of it and then play with curves and levels to increase its contrast, as illustrated in the b channel below.

I now copy this modified channel, go back to RGB, create a new channel, and paste it in. Important note: One can convert freely between RGB and Lab without loss of image quality. CMYK, however, is a much smaller color space, and you can throw away color information by switching to this color space. To avoid this, it may be useful to open a second copy of your image. Alternatively, use the Convert to Profile option instead if Image>Mode>CMYK or RGB, to best preserve the appearance of your original image. In order to combine the nice tree selection with the new channel, separating it from the ground, I paste them on top of the image as new layers. I then lower the opacity of the blue layer to 50%, allowing me to see where the channels differ from one another. I then simply erase. There are other ways to do this using the calculations function, but this is beyond our scope today.

Let's now go back to our first mask (the modified Blue channel), which will allow us to separate the tree and ground from the sky. I copy this channel to the clipboard. I then create two new curves adjustment layers. Adjustment layers (which can be used for curves, levels, hue/saturation, or several other functions) appear with a white box next to them, in which you can mask away the function from part of the image. Alt-clicking on the layer mask (this may be command-click on the Mac) opens up the layer mask, into which we can paste the mask of the tree. I paste it into both adjustment layers, and invert it on one of them. What I've done is create one layer that blocks out the sky (the sky is black and everything else white) and another that blocks out everything else. To smooth the transition between the different adjustment layers, I run a soft Gaussian blur on each of the masks. Because there is considerable fine detail, I run the blur at only 0.7 pixels. This nicely merges the transition between the adjustments and avoids unnatural appearing transitions. I can now modify the tree at will without fear of affecting the sky. When that's done I can fine tune the sky.

I now copy this modified channel, go back to RGB, create a new channel, and paste it in. Important note: One can convert freely between RGB and Lab without loss of image quality. CMYK, however, is a much smaller color space, and you can throw away color information by switching to this color space. To avoid this, it may be useful to open a second copy of your image. Alternatively, use the Convert to Profile option instead if Image>Mode>CMYK or RGB, to best preserve the appearance of your original image. In order to combine the nice tree selection with the new channel, separating it from the ground, I paste them on top of the image as new layers. I then lower the opacity of the blue layer to 50%, allowing me to see where the channels differ from one another. I then simply erase. There are other ways to do this using the calculations function, but this is beyond our scope today.

Let's now go back to our first mask (the modified Blue channel), which will allow us to separate the tree and ground from the sky. I copy this channel to the clipboard. I then create two new curves adjustment layers. Adjustment layers (which can be used for curves, levels, hue/saturation, or several other functions) appear with a white box next to them, in which you can mask away the function from part of the image. Alt-clicking on the layer mask (this may be command-click on the Mac) opens up the layer mask, into which we can paste the mask of the tree. I paste it into both adjustment layers, and [b]invert[/b] it on one of them. What I've done is create one layer that blocks out the sky (the sky is black and everything else white) and another that blocks out everything else. To smooth the transition between the different adjustment layers, I run a soft Gaussian blur on each of the masks. Because there is considerable fine detail, I run the blur at only 0.7 pixels. This nicely merges the transition between the adjustments and avoids unnatural appearing transitions. I can now modify the tree at will without fear of affecting the sky. When that's done I can fine tune the sky.

You can see that the final image is looks natural and was easy to do!

About the Author:

I'm a 31 year old physician, specializing in infectious diseases and tropical medicine at Boston Children's Hospital and Harvard Medical School. I'm originally from Connecticut, but now live in Boston with my wife. My other hobbies are writing, music, hiking, and kayaking. I've travelled extensively internationally for work and study, and my interest in photography is a product of my travels. My Canon Rebel G accompanied me to 6 continents and 15 countries before I finally went digital last year. Much of what I know I've learned from my friends here at Phototakers. Visit Dr. Lantos images at http://drpablo.smugmug.com/