Web Developer Class: How to Mask Images
http://www.htmlgoodies.com/tutorials/web_graphics/article.php/3905841/Web-Developer-Class-How-to-Mask-Images.htm (Back to article)
Masking can be quite simple or complex, depending on the image. If you have a well-defined background then the masking process is relatively simple. In contrast, if your foreground mingles with the background, or if the foreground object has a lot of fine detail such as hair, masking becomes more difficult. One way of making the process easier is if you can photograph your subjects in a photographic studio. With a combination of lighting and high contrast backgrounds you can simplify the process. Real life, however, doesn't always offer those opportunities.
In this tutorial, we will create a relatively simple mask, where we remove a background of sky from an image. Our program of choice is Paintshop Photo Pro X3. Before we get started, it is important to save a copy of the original file. If anything goes wrong with the file you have a backup. Another important step is to make sure you copy the background before you start the masking process. This also preserves the original image.
Another step I recommend is to use a high contrast layer beneath the mask layer. This allows you to clearly see the edges of the mask and will let you know if you need to refine the mask.
To get started, here's an image with a blue sky in the background, which will be easy to mask.
The first step is to activate the Layers palette. To do so, go to View: Palettes: Layers (F8).
Our next step is to create a new layer. To do so, click on the New Raster Layer button at the top left of the Layers palette and in the dropdown list, choose New Raster Layer. In the dialog box, name it: High Contrast.
Make sure the layer is active, then in the Materials palette, click on the color swatch to the right of the rainbow color mixer.
This brings up the Material Properties dialog box. Here, set the color to RGB: 0, 255, 0. Click on OK and use the paint bucket to fill the layer, which gives you a green, high-contrast layer.
The next thing to do is to make a copy of the background. To do so, right-click on the background layer and in the popup menu, choose Duplicate. Double-click on the duplicate layer to bring up the Layers Properties dialog box and name the layer: Masking Layer. The next thing is to click on the High Contrast layer and drag it below the Masking Layer.
Here's what the palettes should look like on the right side of the workspace.
Now we are ready to mask the image. To begin, click on the tool that is third from the top on the Tools bar and choose the Magic Wand tool. If you don't see this, go to View: Toolbars: Tools to activate it.
When you do so, this brings up the Magic Wand settings. Here are the settings I recommend:
Mode: Add Match Mode: Color Tolerance: 20 Contiguous: Enabled Use all layers: unchecked Feathering: 0 Anti alias: uncheckedNow we are ready to mask the image. Note that the cursor has changed to a Magic Wand with a plus (+) sign beside it. This indicates that we will add to the mask as we go along. The next step is to click in all the blue sky areas around the image.
Here's the masking in progress.
If you make a mistake, you can erase it by clicking on the Undo Last Command button or by clicking on Ctrl+Z. If you want to clear the entire selection and start again, click on Ctrl+D.
When you've finished masking the entire image, you're now ready to remove the background. To do so, go to Edit: Cut (Shift+Delete or Ctrl+X).
You can now see through to the high-contrast layer below. The next step is to invert the mask, so you will have the foreground image. To do so, go to Selections: Invert (Ctrl+Shift+I).
At this point you could stop, but you'll find that the masked image may look as if it's been cut out and pasted on to the new image. This is because the mask has a hard edge. In real life, the edges of images have a gradual transition.
Here is an example of an image, which is blending into a background at high magnification. Note the transition. To mimic that effect with masked images, we need to use feathering, which softens the edge, makes it semi-transparent and allows the image to blend into the background.
I have zoomed into the image so you can see the effect. To feather an image, go to Selections: Modify: Inside/Outside Feather.
In the dialog box, on the left is the masked image without feathering. On the right is the image with the inside feathering option enabled and a setting of 14. Note how the edge has softened considerably. This gives you an idea of how feathering works. Once you're happy with the setting, click on OK to apply it. You can now use this masked layer in other compositions.