Lusus

How To Remove The Background From An Image With Gimp


There are a number of ways of removing the background from an image with Gimp, and this is the third method demonstrated on this blog. If you're interested in viewing the other two tutorials, links to them can be found below. Each method has its pros and cons, but I find this one quick, clean and accurate.

How To remove an Image Background Using Gimp

How To Remove The Background From An Image With Gimp

In this tutorial you'll learn how to create a channel layer then use it to create a layer mask. The layer mask will then automatically remove the image background.

For this tutorial the new Gimp 2.10.2 was used, which can be downloaded from the Gimp website here.

Parts of this tutorial are based on a YouTube video by VscorpianC called GIMP Tutorial - Use Channel Mask to Select Hair and Fur but with some important modifications to make it workable for our purposes. Click on each image for a larger view if needed.



1/ Firstly you'll need an image to work with, so sign into Second Life and take a snapshot using a background of uniform appearance, and preferably of a light tone so it is in clear contrast to the subject. I find its usually a good idea to make the snapshot as large as possible.


2/ Open Gimp and load the image. Crop it if you need to. We are going to be using the channels feature in Gimp, the tab for which should be next to the layers tab towards the lower right. If you can't see it click on Windows > Dockable Dialogues > Channels.

With the image layer active click on Select > Save to Channel (see image above).


3/ Under the Channels tab you'll see a thumbnail similar to the one to the lower right of the image above. Don't worry if the channel thumbnail looks completely black.


4/ With the layer thumbnail active select Edit > Copy (highlighted in red, above).


5/ Now Select Edit > Paste into Selection.


6/ In the layers tab you'll see a floating selection which you anchor, naturally enough by clicking the green anchor icon to the bottom right.


7/ Switch back to the Channels tab and you'll see the subject of the image in the red, green and blue channel thumbnails, but more importantly for this tutorial in the Selection Mask thumbnail.


8/ Right click on the Selection Mask thumbnail and select Edit Channel Attributes. The above small window will appear. Make sure the Fill Opacity is set to 100%. Click OK.


9/ Still with the Selection Mask thumbnail active, select Colours > Threshold. I wanted to get a good look at how adjusting the threshold affected the image, so I zoomed in to about 50%.


10/ The small Threshold window will open. The aim here is to use the threshold function to get a black silhouette of the figure contrasted against a white background. We need this because in a moment we will use it to create a layer mask.

The threshold values can be adjusted using the slider. The aim is to keep as much detail as possible in areas such as the hair whilst making as much of the figure as dark as you can. When you have found a setting you like click OK.


11/ Using the threshold function won't create a completely black figure, so some areas will need to be carefully filled in using the Paintbrush tool, with the foreground colour set to black. Remember to ensure you are painting into the Channel Selection Mask since you don't want to accidentally paint into the image layer.

When painting in areas of the figure, you will probably need to change the size of the brush now and then. Neatness and accuracy is essential because what we see as black will make up the visible part of the image, and we want no background showing, just the figure.

Lowering the opacity of the Channel Selection Mask will let you see the figure so you can see where to paint. If you accidentally paint outside of the figure, change the active colour to white and paint out the mistake. When you're finished you should see something like the above image in Gimp. Before moving on, remember to change the Channel Selection Mask back up to 100% opacity.


12/ Switch back to the layers tab and make sure the layer thumbnail is active. Right click on the thumbnail and from the drop down list select Add Layer Mask.


13/ The Add a Mask to the Layer window will open. Make sure the Channel radial button is selected, and tick the Invert mask box. Now hit Add.


14/ After hitting Add you may still see a black silhouette of the figure. Under the Channels tab hide the Selection Mask thumbnail by clicking on the eye icon to its left. Now the figure should be visible in the image window with a clear background.


15/ In the image above there is a small amount of white background remaining to the left of the head. To remove this I clicked on the layer mask thumbnail so it was active then with the Paintbrush tool, and with black as the active colour, I painted it out.


16/ The above image shows the white removed. Maybe the result isn't quite up to a professional photographer's standards, but it shows the method used to touch up a layer mask. (I could have used the clone tool to fill in the small area removing the white patch created, but I was lazy).


With the background removed the image can now be exported out of Gimp, although to keep the transparency of the background make sure to save the gamma when prompted. Before exporting the image a new background can be added instead, and in this example a basic gradient with a drop shadow was used.

As you can see, this method of removing a background using Gimp is very straighforward, and doesn't take long to do. So long as you're careful when adjusting the threshold, pretty much all of the subject's detail remains. Have fun editing your images in Gimp and look out for more tutorials here soon.