<p>Just to confirm, assuming non-premultiplied alpha, at one point you performed the following, per pixel operation:
<span class="math-container">$$ Result_{RGB} = Src_{A} * Src_{RGB} + (1.0 - Src_{A})* Background_{RGB} $$</span></p>

<p>You say you've lost the <span class="math-container">$Src_{ARBG}$</span> data,  but have retained the <span class="math-container">$Background_{RGB}$</span> and the <span class="math-container">$Result_{RGB}$</span>, but want to recover the <span class="math-container">$Src$</span> data?</p>

<p>Unless you can make some other assumptions, you <em>might</em> be out of luck. It's a rather underconstrained problem. 
Jim Blinn notes in "<em>Fun with Premultiplied Alpha</em>" 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'.</p>

<p>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.</p>

<p>If, on the other hand, <span class="math-container">$Result$</span> and <span class="math-container">$Background$</span> don't match, then you know that the source is involved but <em>if</em> the <span class="math-container">$Src$</span>, <span class="math-container">$Result$</span>, <span class="math-container">$Background$</span> RGB values are all collinear, then there could be multiple possible solutions.</p>

<p>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 <span class="math-container">$Src_A$</span>, 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.</p>

CC BY-SA 4.0
2020-05-07T20:48:17.697Z
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.
swestrup
CC BY-SA 4.0
2020-05-06T07:25:13.870Z
2020-05-06T07:25:13.870Z
Simon F
<p>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.</p>

<image-processing><alpha><compositing>
Given a background image B and a composie image of A OVER B, can we somehow recover image A?
swestrup
# Given a background image B and a composie image of A OVER B, can we somehow recover image A?

(Asked by: username_0 on 2020-04-25)

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.

**Tags:** image-processing, alpha, compositing


---

## 1 answers

### Answer by username_1 on 2020-05-06. Score: 0 | Accepted answer

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.

> **Comments:**
> **username_0**: 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.  

---

