0

I have two images:

One with a white background enter image description here

and one with a black background enter image description here

How can I remove the difference and replace it with transparency using GIMP?

2
  • 1
    Hi. Welcome to GDSE. You don't need to do that. The image with the white background already has enough contrast to make a pretty good layer mask. see example. And in any case, setting one layer to difference the other will mess up the word "studio", because they aren't the same colour.
    – Billy Kerr
    Dec 5, 2022 at 0:27
  • 1
    @BillyKerr The red buttons aren't identical either...
    – xenoid
    Dec 5, 2022 at 0:35

3 Answers 3

0

Using a Difference blending mode to create a mask won't really work with these images, because the word "studio" is in black on one image, but white on the other. The word "Amazing" is also different in each image, and the red dot of the "i" isn't identical in both images either, as @xenoid points out in a comment.

I mean you could try it and see for yourself. Put the black background image above the white, and set the layer blending mode to difference. Create a new layer from visible, invert it, and copy and paste the result into a layer mask on the white background version, and anchor it. Delete the unwanted layers. But the mask will need considerable fixing.

In my opinion, you don't need to do any of that anyway. The image with the white background already has enough contrast to make a pretty good selection of the white background. My approach would be similar to xenoids answer, except that I'd probably use the selection to create layer mask - which gives you a little more leeway to fix things if the mask isn't quite right.

enter image description here

5
  • This has the opposite effect of what I want - The background is kept while the rest is replaced with transparency (i.stack.imgur.com/LUv2p.png). How can I do the reverse?
    – myself600
    Dec 5, 2022 at 10:27
  • @myself600 Yes, that's why I said you need to invert it. All you need to do is select the mask and do Colors > Invert. Or when creating a mask from a selection, there's an invert option in the Add Layer Mask dialog
    – Billy Kerr
    Dec 5, 2022 at 11:16
  • After several attempts, I was finally able to do it: i.imgur.com/WjCMioV.png (I used "Colors -> Invert" and "Copy Visible"). However, there are still grey edges when displayed against a dark background (I expected it to be closer to original than when using the Wand tool). Regarding the edges, is there some other method outside using the Wand tool as suggested by @xenoid that would come close to what moving the opacity slider does on the Layers tab?
    – myself600
    Dec 5, 2022 at 12:38
  • @myself600 - I've added another answer. Check it out
    – Billy Kerr
    Dec 5, 2022 at 13:18
  • I've marked this as a direct answer to my question even tho it wasn't the optimal one, as that would be the combination of Wand threshold and "Grow selection". Thank you both BillyKerr and @xenoid for your input!
    – myself600
    Dec 5, 2022 at 17:43
0

My usual technique (applies to both):

  • Wand-select the background
  • Don't forget to include isolated areas (the two Aa of Amazing, the D and O, and four triangles in the logo), by shift-clicking in them to add them to the selection. Don't be clever and use color selection instead to avoid this.
  • Select > Grow by one pixel so that the selection includes a one-pixel edge of the previously un-selected areas
  • Set the bucket-fill tool to "Color erase" mode, and Fill whole selection

enter image description here

  • Bucket-fill with the color to erase

Composite image of the results, over contrasting background to check the edges:

enter image description here

10
  • I usually do the same too with a minor difference: use the picture with black background as the edges would be less noticeable against light colors, use Wand tool with highest threshold possible that does not leak into the objects, hold Shift to select all the parts to remove, invert selection, select none, Ctrl+X, 2 steps back in history, Ctrl+C, latest history, Ctrl+V. The problem with this approach is that it's not perfect.
    – myself600
    Dec 5, 2022 at 10:24
  • The "minor difference" is fundamental. With a plain selection, the pixels on edges are either fully selected or not selected, so you get a jagged edge (too much selection, or a rim of remnants (not enough selection) and there is no "just right" setting; The technique above is different, it transforms th epixels on the edge to partially opaque pixels so that they blend correctly in any background. See this for more explantions.
    – xenoid
    Dec 5, 2022 at 10:44
  • The only difference is using "Grow selection" to catch the surrounding pixels that would otherwise not be made transparent and yes, it seems to solve the issue of grabbing all of the anti-aliased pixels. Thanks for the suggestion!
    – myself600
    Dec 5, 2022 at 11:27
  • No, the big difference it the Color erase painting...If you image has a strong contrast (says, black text on white) you don't even need the selection. The selection is only used to keep opaque areas of the subject that could have some erasable color.
    – xenoid
    Dec 5, 2022 at 11:32
  • Nothing happens when I bucket fill the background for some reason i.imgur.com/2OjQ50i.png i.imgur.com/NLaa9Ba.png - I've used "Color to Alpha" instead
    – myself600
    Dec 5, 2022 at 13:06
0

Here's another method, this time to counter the problem of anti-aliased pixels in the mask leaving an outline of greyish pixels, and also keeping the anti-aliasing of the original intact so that the edges look smooth and not jagged.

  1. Open the image with the white background, right click it in the layers panel, and choose Add Alpha channel. If this option is greyed out, there's already an alpha channel and you can skip this step.

  2. Select all the white areas using the Fuzzy Select tool, including the insides of the letters A,a,D,O, and also not forgetting the 4 little white triangles in the logo. Holding down Shift as you click allows you to select multiple areas.

  3. Do Select > Grow, by 1px

  4. Do Select > Invert

  5. Create a new transparent layer and drag it to the bottom of the layers stack

  6. Select white as the foreground colour in the toolbar, and do Edit > Fill with FG color. This will fill the selection with white. This layer will act as a base fill layer.

  7. Do Select > None

  8. Select the top layer in the layers panel

  9. Do Colors > Color to Alpha, and click OK

Here's the result

enter image description here

Add a contrasting fill underneath, and zoom in. There should be no problematic pixel outline. Here's part of the image at 100% zoom

enter image description here

Note: If you think the logo has become too light here, you can duplicate the color to alpha layer, and adjust it's opacity to adjust the lightness/darkness.

4
  • Color-to-alpha no longer works perfectly in 2.10 as it did in 2.8. Bucket-filling with Color erase is a better way in 2.10 (it can also be used by painting a layer above, and setting the layer to Color erase).
    – xenoid
    Dec 5, 2022 at 16:00
  • @xendoid, I used this in 2.10 - seems to work fine. The result is pretty good IMHO
    – Billy Kerr
    Dec 5, 2022 at 18:18
  • This still uses the Wand tool. I was thinking about something within the Layers tab, like different order of the black/white image layers and/or other mode than "difference". I initially though than transparency could be recovered in an "automated" way (rather than guessing the Wand threshold+Grow selection values) since there are two sources (and I only need the triangle logo anyway). If I understand, the transparent layer will act as a mask to know which pixels should not become transparent.
    – myself600
    Dec 5, 2022 at 18:19
  • @myself600 - there's nothing automatic that can do what you want. Sorry. Not even Photoshop can do this perfectly to be honest. It's going to need some tweaking, to get the best results. The difference method is practically useless for most background removal jobs anyway. Hardly ever a good idea.
    – Billy Kerr
    Dec 5, 2022 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.