I'm wondering if there is a way to automatically calculate transparent image from set of non-transparent ones. No manual work with individual pixels or manual setting of opacities.

Many times I need to export images from "image editors" which are not supporting transparent backgrounds (example: PowerPoint). I can still give the image any background. For example I'm able to export two samples with mutually inverse backgrounds (as seen on 2 samples below). Or I can create 3-5 images with backgrounds for example: red, green, blue, white, black.

2 samples with mutually inverse backgrounds leading to expected result (I'm seeking technique/plugin to get such a result):
enter image description here

With such a set, based on differences between samples it should be completely clear what pixel has what alpha value.

Is there a method/plugin for converting set of samples described above into single image with correctly derived transparency?

I prefer GIMP.

One more sample to illustrate the idea. Semi-transparent glows are used:

enter image description here
enter image description here

  • You could do something like this using ImageMagick, but the semi-transparancy of the drop shadow would be a problem.
    – JohnB
    Commented May 16, 2014 at 13:40
  • @JohnB – I think we can agree mathematically it shouldn't be a problem also for semi-transparent pixels if source images have specially chosen background colors. I'm wondering if there's a technique/plugin to do the math :)
    – miroxlav
    Commented May 16, 2014 at 13:43
  • Alright, think I get it now. Would this be a correct rewording of the question? --- Is there a plugin or method to isolate the identical parts of a set of images and changes the rest to be transparent?
    – Ryan
    Commented May 16, 2014 at 13:46
  • I don't know what sort of solution you're looking for, but GIMP can do this with "Colour to Alpha", and Photoshop can do it with "Select -> Color Range...", I don't know how you'd automate it with GIMP, but it could easily be made into a photoshop action.
    – OGHaza
    Commented May 16, 2014 at 13:50
  • @miroxlav yep agreed. Just not sure that sort of calculation could be done with IM. Perhaps someone more knowledgeable than me knows!
    – JohnB
    Commented May 16, 2014 at 14:01

2 Answers 2


This can be 'perfectly' done. You need to align the two images as Horatio says. However I'm going to attack this mathematically.

So you have 4 channels to fix. Alpha channel is easiest. Place the layers on top of each other and subtract the orange layer for the blue one (this gives better contrast). Then open your channels box duplicate the layer with the most color difference.

enter image description here

Image 1: duplicate the channel with most color difference.

Run levels on the copied layer so the brightest color is white using the with the point picker. Don't adjust gamma or black point. This is now your perfect (albeit slightly color resolution challenged) alpha channel. Invert the copied channel.

If you were to apply the alpha now on the picture you'd be left with the pre-multiplied color cast. This would be easy in after effects but in Photoshop you have to do the heavy lifting yourself. Defringe might work for some simple cases but there's a better way that's guaranteed to be as good as possible.

To remove the matte make a new layer. Fill the entire layer with the background color. Then load the alpha and fill it with black, this is your color matte screen .Be sure this is NOT cut from the image with color variation or you taint the process (unless you plan to remove background instead of matte but that's another math sequence).

Color matte screen

Image 2: Color matte screen.

Subtract the color matte screen from your color layer. This gives you the color channel.

Color Channel

Image 3: Color channel.

Now you still need to merge the alpha and the color channel together. So merge the color channel layers together. Then load the copied channel as a layer mask.

So now we only have one problem, Photoshop uses Straight matte. Yes that's right pixels have the fully saturated color of regardless of alpha. So apply the mask to the layer. Then run Layer -> Matting -> Remove Black Matte

Final result

Image 4: Final result.

And this is nearly as good as it gets. I calculated that I would have gotten one alpha level more if I had done a plugin. Mainly because i could roll the defringe into the operation stack.

To automate:

You can make a action out of this and its always one color picker away form automatic. This could be scripted but i have other things to do. Anyway i described all the math that goes into this.

PS: i asked for the black background as it would have made it one step shorter.

  • This looks good! Thanks for more mathematical approach. Will this work with colored semi-transparent areas I recently added to the question? (We were working in parallel :)
    – miroxlav
    Commented May 16, 2014 at 18:45
  • @miroxlav Yes. The only snag is that the bg colors you use aren't 100% ideal in terms of contrast but other than that slight loss of possible alpha resolution no problems. Uisng white or black matte would be a good idea.
    – joojaa
    Commented May 16, 2014 at 18:48
  • – bg colors were intended just to allow detection of transparency. One of output results could still be permanent bg transparency, for example as used with design of desktop icons.
    – miroxlav
    Commented May 16, 2014 at 18:50
  • Let me try this out by myself...
    – miroxlav
    Commented May 16, 2014 at 19:04
  • Couldnt you just do the alpha by changing everything by black/white in the source app? Maybe this wouldn't work for your glows? Anyway im pretty sure one could read PowerPoints alpha channel.
    – joojaa
    Commented May 16, 2014 at 19:17

Take "image LEFT", place on layer above "image CENTER" so that they are perfectly aligned. Use the "subtract" layer blend mode. Anything that is the same will be black.

Flatten the image, copy all, undo flattening, and then paste to new layer. Select via color on the black with the widest "fuzziness" setting. Hide the layer and apply the black selection as a layer mask to either LEFT or CENTER image.


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.