All photographs and articles on this web site are Copyright © Eric R. Jeschke (contact info ).

Creative Commons License Text and/or images are available for personal or commercial use under certain conditions.

Site designed for screen resolutions of 1024x768 or greater. You may wish to maximize your browser for best viewing.


Simulating Shallow Depth of Field with The GIMP


Before After
One of the facts of life of shooting with consumer digicams and their associated small imaging sensors is that it can be difficult to achieve a shallow depth of field. Having large depth of field is usually a good thing, leading to pictures in which all of the important parts of the picture are in focus. But sometimes you really want shallow depth of field to isolate a subject against a blurred background, as is often done in e.g. portraiture.

In this tutorial I'll show you how to simulate a shallow depth of field using image editing techniques. It is painstaking enough that it is no substitute for having camera equipment that is capable of the job. Nevertheless, it can be useful in rescuing the occasional picture.

The Procedure

As with many of the other tutorials on this site, the beauty of this method is in the use of layers. A duplicate layer is blurred and a layer mask added to make the subject transparent. The original image remains unsullied in its own layer.

Load your image into the GIMP.

I thought this portrait would look better if the background wasn't quite so distracting.

The most difficult thing we will have to do is creating a mask for the subject. We will try to find the "natural mask" that is already in the image and so use this to make our work much less tedious.

The best contrast between items can often be found in the green channel. It's a good place to start looking, in any case. So the first thing we will do is decompose to individual RGB channels.

Right-click in the image and choose (Image/Mode/Decompose). In the Decompose dialog box, choose RGB and click OK.

Examine each channel to find which has the best contrast for isolating the subject. In this case the green channel image was the best.

Close the other two images that you aren't going to use. With a little work this green channel image will become our mask.

First we'll minimize our work by drawing a selection outline around the subject with the lasso tool ().

Now invert the selection (Ctrl+I), choose the fill tool (), make sure Black is selected as the foreground color and click in the image.

Clear the selection (Shift+Ctrl+A). You should see something as shown on the right.

Now we want to try to force the outline of the subject to white. Right-click in the image and choose (Image/Colors/Threshold).

In the Threshold dialog click in the histogram and drag to the right, as if you were selecting the right half. You will see the image go to black and white, with everything to the left of the selection going to black, and everything in the selection going to white. Experiment with different selections until you have one that gives the best isolation of the subject in white.

When you are satisfied, click OK.

We're going to manually touch up the mask to fix any last imperfections. Here's where the work can get a bit tedious. If you've found a good contrast between subject and background and exploited the lasso, fill and threshold steps well you shouldn't have too much drudge work at this step.

To help us out we're going to composite the mask and the image. Open the Layers dialog (Ctrl+L) and click on the New Layer button (). Name the new layer "Mask Guide".

Now go to the original image window (you didn't close it did you?). Select All and Copy (Ctrl+A then Ctrl+C). Now go back to the mask image and paste into the new layer (Ctrl+V). It should paste as a grayscale image. Finally, in the Layers dialog, anchor the pasted image and reduce the opacity of the Mask Guide (upper) layer to around 70%, as shown. The image should look something like what is shown in the lower right.

What this does is allow you to view the image and the mask at the same time, overlayed, while you work on the mask.

Before you leave the Layers dialog, select the Background layer in the mask image (that's the layer we want to work on), as shown at right. The Mask Guide is just to guide us.

Select a reasonable brush (usually small and fuzzy) from the Brushes Dialog (Ctrl+B), select the Paint tool () and begin painting the mask. You want the subject in White, anything that is not the subject should be Black.

You'll probably need to use a few different brushes. Zoom and pan around the image. Switch back and forth between Black and White (x) and take lots of small steps so that you can make use of the excellent Undo capabilities of the GIMP.

Periodically you can turn off visibility of the Mask Guide (by clicking on the "eye" next to that layer in the Layers dialog) to view your mask's progress.

When you are all done, I suggest saving the mask (as an XCF file) so that all that painstaking work does not have to be replicated later if you decide to re-edit the image.

Do a small Gaussian Blur (Filters/Blur/Gaussian Blur (IIR)) of about 5 pixels or so on the mask.

Then invert the mask (Image/Colors/Invert).

In the Layers dialog, select the original image in the drop down box. Then click the Duplicate Layer button ().

Double-click on the name of the top layer. In the Edit Layer Attributes dialog, rename the new layer "Blurred".

In the original image window, right-click and select (Filters/Blur/Gaussian Blur (IIR)). Experiment to find a value that works well for your desired "depth of field". Generally you won't want to go too crazy with this or the look will be all wrong. Here I used a value of 40.
Go back to the Layers dialog and right-click on the "Blurred" layer; select "Add Layer Mask". In the Add Mask Options dialog make sure White (Full Opacity) is selected. Your Layers dialog should now look as shown at right.
Go to the mask image window and Select All and Copy (Ctrl+A then Ctrl+C). In the original image window, Paste (Ctrl+V). This should paste the inverted mask into the layer mask.

In the Layers dialog, click on the anchor button to anchor the pasted image.

Voila! Your subject should be clear and sharp, while the background appears soft and out-of-focus.

Tips

For Further Reading



Last modified: Sun Jan 9 21:02:09 HST 2005

Creative Commons License Text and/or images are available for personal or commercial use under certain conditions.

Contact Eric Jeschke

Powered by Google