I often find myself in the situation where I have some old image where I composed a translucent overlay on top of a background, but then lost (or more likely discarded) the overlay. I still have pre-operation copies of the background, but have not managed to figure out how to perform an inverse operation to calculate the original overlay. Best results would be an operation I could perform in Gimp or Image Magick, but I could write an uncomposer if I had to, so long as I knew what to calculate.


1 Answer 1


Just to confirm, assuming non-premultiplied alpha, at one point you performed the following, per pixel operation: $$ Result_{RGB} = Src_{A} * Src_{RGB} + (1.0 - Src_{A})* Background_{RGB} $$

You say you've lost the $Src_{ARBG}$ data, but have retained the $Background_{RGB}$ and the $Result_{RGB}$, but want to recover the $Src$ data?

Unless you can make some other assumptions, you might be out of luck. It's a rather underconstrained problem. Jim Blinn notes in "Fun with Premultiplied Alpha" that there are some commercial systems that are used to 'de-bluescreen' but they may require the operator to identify, say, what is 'Source' and 'Background'.

As an extreme example, you may have a pixel in the result which exactly matches the background but the source pixel may also have been the same colour.

If, on the other hand, $Result$ and $Background$ don't match, then you know that the source is involved but if the $Src$, $Result$, $Background$ RGB values are all collinear, then there could be multiple possible solutions.

Having said this, there may be some heuristics that perhaps could be used, but it'd require some thinking. Perhaps, pixels which differ and are not collinear could be used to estimate $Src_A$, with some level of 'certainty', and this could be 'filtered' to neighbouring 'uncertain' pixels and the process repeated. Non-constant pixels in the destination with a local neighbourhood which all match the background might be assumed to have an alpha of 0.0.

  • $\begingroup$ Yes, if a pixel is assumed to have a single color value, then its underconstrained. If we treat each pixel as 3 color channels, each of which has to solve the above equation with the same reconstructed alpha, it seems a bit more tractable. Even then, I fear there may be corner cases. $\endgroup$
    – swestrup
    May 7, 2020 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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