Background Zapping

This example was using Gimp 2.2

Before one can do anything much with a photo of a person, one needs to separate the person from the background.

  1. Obviously, the first thing to do is open your chosen photo-image.
  2. Open "Layers, Channels" window and duplicate the image layer. (call them p1 and p2)
  3. Make a new completely white layer (call it "white" if you like). Move it in between p1 and p2 (p1 at the bottom). If the original image has a lot of white in it, then colour the White layer a colour that isn't in the image, like a light lurid green.
  4. Add a Layer Mask to the layer p2, (right-click on the layer in the Layers window -> Add-Layer-Mask). In the window, select either "Grayscale copy of layer" or "White".
    1. If you selected "Grayscale copy of layer, you will now see a very strange image, with part of the image showing like ghosts and part completely white -- the white bits are the White layer showing through.
      1. Make sure the layer mask is active. Use the Threshold tool (Layer -> Colors -> Threshold) to adjust the colours of the mask so you get a good portion of the part of the image you want to keep.
      2. Sometimes it's better to select the background and then do an Invert (Layer -> Colors -> Invert).
    2. If you selected "White", then you will see your image with no change. It is best to select "White" if your background and foreground are very similar, since you won't get much benefit from the "Grayscale copy of layer" method.
  5. You now need to refine the layer mask; there are a combination of techniques:
    • Use the "Select congiguous regions" tool on the image layer (p1 or p2) and then use "bucket fill" after re-activating the layer mask layer.
    • Use some other selection tool likewise.
    • Paint the mask directly with the pencil tool.
    Remember that black makes something transparent, and white makes it opaque.
  6. If you make the White layer semi-transparent, you can see the original image through it; this can help with penciling on the layer mask.
  7. To double-check that you don't have any odd specks you've missed, turn on the display of the layer mask (Layer -> Mask -> Show Layer Mask) and paint over any stray bits. Then hide the layer mask again.
  8. When you're fairly satisfied with the Layer Mask, apply a small blur to it (Filters -> Blur -> Gaussian Blur) to soften the edges.
  9. I usually make the p2 layer truly transparent by adding a transparent layer below it, and then doing Merge Down (right click in the layer and get the layer menu). Then you end up with a layer with just the person in it.

Now that you have a layer with your person on it, with the rest of the layer transparent, you can go off and do exciting things with your picture.

A Note for those confused about Step 4

The way it works is, the layer mask is a grayscale "mask layer" associated with a given normal layer. Where the layer mask itself is black, the normal layer is transparent. Where the layer mask itself is white, the normal layer is completely opaque. Where the layer mask itself is some shade of grey, the normal layer is semi-transparent.

What happens when you select "Grayscale copy of layer" when creating the layer mask, is that the layer mask will be pre-filled with a grayscale copy of the normal layer -- so where the normal layer is dark, the layer mask will be dark (and thus the normal layer will be made near-transparent) -- and likewise where the normal layer is light, the layer mask will be lighter, and more of the normal layer will show, being more opaque. This gets slightly confusing because, remember, we have added, underneath our layer, a plain white layer. Thus, where our chosen layer is showing transparent, it will appear white, because the white layer below it is showing through.

We then want to use the "Threshold" tool because we want our layer mask to be pure black and pure white -- areas that are totally transparent, and areas that are totally opaque, since the purpose of this exersize is to eliminate the background we don't wish to see. When you apply the "Threshold" tool to the layer mask, then the grey parts of the mask will be forced to either black or white -- and you can move the slider along to adjust this, to try to get a result where the fully-opaque areas (that is, those areas which are white in the layer mask) are those areas you want to keep, and the fully transparent areas (that is, those areas which are black in the layer mask, and appear to be white in the image you are looking at, because of the white layer below, showing through) to make sure that those areas are those you don't want to keep.

Sometimes it is easier to do it the other way around, for example, you have a person with dark hair against a light background, then the natural way the "layer mask with grayscale copy of layer" will turn out, is that the background will be opaque (since it is lighter, and the "Threshold" tool will thus push it to be white) and the hair will be transparent, and the face (again because it it lighter) will be opaque. In that case, you move the slider of the Threshold tool until you can see the border of the person's hair, and the background, hit "Okay" and then use the Layer -> Colors -> Invert tool on the layer mask, which will get you the background transparent, the hair opaque, and the face transparent (and then you can make the face opaque by making the layer mask active, and painting in the face area with white).