I'm "reverse engineering" a graphics package based on rasterized images to recreate the graphics package as layered components.

I have a situation whereby I have two elements, each with some level of alpha transparency, that were layered on top of each other. I know the color of the background element as well as the resultant color. How can I find the original color and transparency of the foreground element?

Better yet, how can I separate these two elements such that when I rebuild them on top of each other, they look like the original?

Is there a way to do this within Adobe Photoshop or perhaps an online utility?

Background Purple: rgba(81,16,110,.88)
Resultant Purple: rgba(48,15,65,.95)
Foreground Purple: ????

Here is a sample image for reference: Rasterized Elements

UPDATE I understand the basic math behind calculating this manually, as detailed here, but this doesn't really work well for more complex alpha de-compositing. Like in this example: Rasterized Gradient

Is there a way to subtract an rgba value from all pixels in an image?

  • Please note that the areas where transparency is 100% opaque can not be solved.
    – joojaa
    Commented Mar 6, 2016 at 19:26

1 Answer 1


One can easily reverse engineer this image. the transparency grid of a screen capture makes it slightly harder for me to verify but still not a big problem you'll just have to calculate yourself. Alpha blending is:

total_Alpha = top_alpha + bottom_alpha(1-top_alpha)

so in this case we get:

0.95 = x + .88 (1-x) =>
0.95 = x + .88 - .88x =>
0.95-0.88 = 0.12x =>
x = 0.07/0.12 ≈ .58

Now this is correct if you measured correctly but i have some doubts about that but since you show it on a transparency grid i wont bother to verify my calculation.

total_RGB = (top_rgb*top_alpha + bottom_rgb*bottom_alpha(1-top_alpha))/total_alpha

Where its convenient to calculate with float colors so colorshannel/255 in your case. I will leave this calculation for you to do.


Photoshop can do calculations on individual channels. Its just a bit messy for several reasons. First, Photoshop can not handle negative values. So you would need to offset the values appropriately, this work fine if you turn floating point precision on. Without floating points otherwise values above max in addition to values under zero will clip, take care. Second the GUI is messy and you can not just type in your operations.

Basic channel calculations are available in Image → Calculations, this allows you to do calculations on one channel at a time. Calculations allows you to do all the basic mathematical operations, add, subtract, multiply and divide for all pixels in one go for one channel. With the limitation in mind this should be doable.

enter image description here

Image 1: Calcualtions.

Tip: Record your calculations into an action. If you screw up then it's easy to backtrack where you left off.

Second layer modes Multiply, Add, subtract and Divide do exist. They work pretty well on color channels if you do not have an alpha in the images. Again no negative values available so be sure to calculate so your values do not clip.

examples of me doing almost what you ask can be found in following post:

Note: All this said, I would still suggest you use something like numpy, matlab, Mathematica even imageMagik for the job it is MUCH faster to develop and use. Due to this I'm not going to do the calculations for you.

Note 2: Some cases can not be solved as theres no way to separate alpha contribution and color. Most notably when the sum of the layers alpha is 100% than you will not be bale to deduce the alpha value. And thus you can not know what the color is without guessing.

  • This is essentially what is already listed on Wikipedia here (en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending). Do you know of a way to automatically do this in Photoshop or some other utility? The manual technique you mention works for basic elements, but doesn't really work well for gradient elements. I'm basically looking for a way to subtract a specified rgba from all pixels. Commented Mar 6, 2016 at 5:52
  • you can do calculations in photoshop. but its a bit convoluted id rather not write step by step instructions for this as it takes a few hours to do. It would be less work to write a new software for this. @BigMacAttack yes alpha blending is well known stuff. But i think i have written this instruction allready once ill search.
    – joojaa
    Commented Mar 6, 2016 at 8:32

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.