Remove background from an image with Gimp and Masking

This skill is useful as you can take pics of your friends and place them in different places that they have never been! There are a couple of tricks to make your work easier and results look better. I’ve written some notes to accompany this video, but there’s also 2, 3, 4, 5, 6

Import the image, add transparency
Once you import an image it will not have transparency. For this you will need to highlight the layer, colors-> transparency -> add alpha channel. You will notice that the layer name goes from bold to not bold. Duplicate the layer, just in case of a mistake.

Images by default do not come with transparency, so you need to add it. This way part of the image can be see through.

Images with a high contrast between what you wish to preserve and what you want to remove will be much easier. Images that have similar colours between the two will be much more challenging.

Getting your Mask
A mask is the layer that highlights what you wish to see and what you wish to remove. There are may ways to get a mask. For example you could use the magic wand and trace out your highlighted image, but this is tedious, time consuming and may not be so accurate.

One way is to use colour contrast. On the mask layer, color -> desaturate, followed by color -> brightness-contrast. Play around with this to get the best contrast between the parts you wish to keep and the parts you want to remove. This can provide a very fine level of detail for things like hair.

Next do a color -> invert, which reverses black and white. In a mask, the white allows the underlying image to show through, and the black will block the underlying image. You can now use your tools to reshape your image to black and white, depending on what you want to show up. You can use a paintbrush in white to allow things to show through. Use squares in black to remove background parts of the image. Some details, such as hair will inevitably be lost.

Of course it would be much easier if you had an image that is high in contrast between what you wish to keep and what you want to remove. Often there are background colours that are similar to the image you want to keep. These will need to be altered by hand. This can take a lot of time and patience, but the better a job you do with the mask, the better the overall final image.

For example, black hair will turn out white, which you wish to keep. The face, however will turn out black, so you will need to paint the face white in order to preserve it. Ditto for clothing, which will need to be painted white to preserve it.

Add Mask to your Image Layer
Save your image. Cut the complete layer, edit -> cut, and the layer will disappear. Don’t worry, it is in your clipboard. From your original image layer layer -> mask -> add layer mask. Use the default “White (full opacity)”, which allows you to use white to see the image, and black to block the parts you don’t want. You will see that in your layer there is a white box that is added to your layer image and name. Highlight the layer edit -> paste, to add your mask to the layer. You will see a “floating layer”. Right click the floating layer and “Anchor Layer”.

Your image should have changed. Where you painted white you will see the underlying image. Where you painted black you should see only the transparent background. You can now add a solid colour background to your image, which will allow you to see any mask errors. You can continue to fix these errors, painting using white to allow the image to show up, and black to remove the background. Zoom in, paint with either white or black, for finer detail. The better your mask will result in a much better overall result.

The benefits of this brightness-contrast method is that a lot of fine detail can be preserved, which you would lose if you simply did a lasso. You can zoom in and add more detail. If you make a mistake, repaint with white and redo your black. This is very forgiving.

Add a New Background
Find an image of an appropriate size and add to the background. Your foreground image will be preserved, the transparency will allow the background to show through. You can then export the image. You can add as many background images as you wish and export individual images.

Blur Background, Keep Foreground Sharp
Here is a video about how to blur the background but also keep the foreground clear. It is an impressive trick. I’d still use the brightness-contrast filter to do the outline, as using the lasso tool is not very precise. The methods of the mask do overlap.

Leave a Reply

Your email address will not be published. Required fields are marked *