Consider the following graphic:


Note that the first image's background is transparent, and that the blue background in the second and third images is a subtle gradient - not solid color.

Basically, give the 2nd image and the 3rd one, how can I find the difference between the two to (roughly) generate the 1st image?

I'm open to any kind of answer, from "how to do it in %Program%" to "find the difference between both rgb values and multiply by..."

PS: I just realized I switched the first image with the second one in the graphic. Obviously, you start with the gradient and then put the overlay over it.

PS: GIMP has a feature called "Replace Colour with Alpha", basically, it does what I need, but it uses a specific color. In my case, the color would depend on the position.

  • I think this might be easier to understand if you made the blue gradient more obvious?
    – e100
    Commented Jul 19, 2012 at 11:28
  • Also, I assume there is alpha transparency in the 1st image?
    – e100
    Commented Jul 19, 2012 at 11:41
  • @e100 Yes and yes. Actually, I believe the first two sentences explained the situation nicely?
    – Christian
    Commented Jul 19, 2012 at 14:54
  • Does this answer your question? How to remove backgrond using a photo with only the background? (GIMP/others)
    – Billy Kerr
    Commented Jun 28, 2021 at 13:48

1 Answer 1


If you have imagemagick installed (if you don't and are on a mac I'd recommend using homebrew) there is a super-easy way that will get you close...

see this article here: https://legacy.imagemagick.org/Usage/compose/#changemask

Basically from your two images you can call this command...

convert original.png background.png -compose ChangeMask -composite result.png

with the image with everything being original.png, the blue gradient background being background.png and the output (transparent) being result.png (or whatever you want it to be called).

enter image description here

You can see the result above... it successfully strips the background away, but the anti-aliasing of the items is still somewhat blue.

Maybe this is enough for you... if not things become much more difficult quickly.

The problem is that it isn't obvious with those edge pixels what colour/transparency combination they are.

There are techniques to help with this which you can read about in more details here:

But it is non-trivial to achieve as far as I know.

To get a really good result ideally you have two versions of the image sat on different backgrounds (white & black is classic) and then this technique works:


Anyway, fingers crossed the first option might be enough for your needs.

  • 1
    Thanks for the (very) informative reply, highly appreciated! While at the moment I do not have a specific problem to tackle, I was curious as to what possible ways it can be achieved. Usually, I end up doing this kind of thing manually (replacing blue in the edges manually, for example).
    – Christian
    Commented Jul 19, 2012 at 21:52
  • no problem! the first approach will definitely save you a bit of time getting rid of the main areas of background, in that case.
    – Chris
    Commented Jul 20, 2012 at 10:49
  • "To get a really good result ideally you have two versions of the image sat on different backgrounds" - very interesting. Would be interesting to try this out for a physical semi-transparent object.
    – e100
    Commented Jul 20, 2012 at 11:47

Your Answer

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

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