# Substract two images

Let's say I have 3 images `A`, `B` and `d` with `B = A + d`. Here, `d` is a semi-transparent image. If I have `B` and `d`, is there a way to get A?

A:

B:

d:

I've tried to follow the instructions here but it didn't work.

• Never done this, so I won't answer, but your math as stated is reversible: B=A+d therefore B-d=A. I expect that a uniform transparency value (say 80% opaque; t = .8) can be applied to d first, so B=A+(td) and therefore B-(td) = A. Ignoring rounding, the main hang-up here are clamped values at 0 and 255 Jun 10 '16 at 16:45
• Does this answer your question? I think thats what you're trying to do, right?
– Cai
Jun 10 '16 at 16:50
• It's exactly what I'm trying to do, but it doesn't work. I'm getting this: image Jun 10 '16 at 16:58
• Why do you say it's d/2 ? Jun 10 '16 at 17:07
• oops meant to say (A+d)/2 because after i subtract d from B i get a darker version of A Jun 10 '16 at 17:09

Yes you can do this you will lose some stuff in rounding errors and dynamic range. just subtract the image from the background. Tough it does not seem like your operation is add. its possibly add plus a channel normalization. But yes i can reverse this by subtracting the mask and re normalizing the levels.

Image 1:B-d

Image 2:B-d + Normalized levels

I lose some color dynamic but that's all. Whether or not that is too much or too little deepens on picture. Could i do it in opposite direction so B-A. i could but the dynamic range is already pretty weak

Image 2: Inverse A at 36% + B

Please note: I am only able to do these operations because i know what the images were and can search them.

• Hum. In my opinion too much info is lost. :oP But I deleted my answer. Jun 10 '16 at 18:46
• @Rafael deepens on image in the case of this image not much was lost. Anyway the operation most certainly is not just add Jun 10 '16 at 18:46
• I deleted my answer! What else do you want!? Do not humiliate me more n_n Jun 10 '16 at 18:48
• @Rafael no at all i just pointed out that for most images this would be terrible yes but this image seems to have so little contrast dynamic that it does not really matter that much. Most images would't survive. I agree with that. Jun 10 '16 at 18:49
• Thanks for the answer. By the way, bonus question: is it possible to do the same thing but with A and B? (get d) Jun 10 '16 at 18:49