Gimp-Forum.net
Remove background with image of the Background - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: General questions (https://www.gimp-forum.net/Forum-General-questions)
+--- Thread: Remove background with image of the Background (/Thread-Remove-background-with-image-of-the-Background)



Remove background with image of the Background - Guppy - 02-23-2023

Hey everyone! 
I have 2 Screenshots from a game. One is a textured Background. The other is a screenshot of a bear in front of the same background. Now I want to remove the background from the bear-image, so that only the bear remains with a transparent background. So to say, every pixel that is the same in both images should be deleted, but the differences (the bear) should stay. I don't know if the background is exactly the same, so a little bit of Variation might be required. 

Is this possible with Gimp? If yes, how can I do it? 

I already found the "substract" option in layers. This creates a black background, with the bear silhouette visible. but "inside" the bear I can see the textures of the background, not the bear itself.  I want the bear in its original form and the background transprent instead of black. 

Thank you for all your answers!


RE: Remove background with image of the Background - PixLab - 02-24-2023

Mode Difference, Exclusion, Subtract, etc... in this section are good helps to separate a BG, you did well, now you just need to use that "visible" as a layer mask Wink

With the subtract mode on top, all the BG black, and that top layer selected in the layer's stack/dialog, right click on it > a context menu opens, select "New from Visible", select that "Visible" layer, make it B&W (Colors > Desaturate > Desaturate), increase contrast to better separate black from the subject, may be paint a bit some white on the subject to fine tune, and then use it as a mask on the needed layer.


RE: Remove background with image of the Background - rich2005 - 02-24-2023

You might get it using a differenced pair of images.

This a possible procedure: too many screenshots so put as a sequence in the attached PDF. edit: This is similar to PixLabs comments

(1) The pair of images
(2) The images differenced to give that black background.
(3) Get a 'flattened' version of that using Image -> New from Visible
(4) Use the Fuzzy select tool to select that black background. To avoid unwanted border pixels use Select -> Grow by two or three  pixels.
(5) Back down to your main 'bear-on-background' layer and turn off the visibility of the other layers. Add a layer mask. Layer -> Mask -> Add Layer Mask. Choose the Selection option and tick the Invert Mask. Using a Layer Mask gives the option to do any repairs such as painting out remaining background etc.
(6) That masks out the background. Kill the selection. Save your work as a Gimp .xcf in case you need to go back for more work

When complete you can export as a png to keep the transparency (a game ? or maybe as a gif )

If that does not work there are other ways of getting that first selection to make the mask. The ForeGround Select tool or drawing round with the free select tool. The Gmic plugin http://www.gmic.eu also has a fg extract filter - this from another post https://i.imgur.com/HrP2gjG.mp4
There are all sorts of ways.