I have two images, one with a white background, and one with a black background, I want to convert these images into one semi transparent image
I have found that
color*alpha=blackBackgroundImage
color*alpha+(1-alpha)=whiteBackgroundImage
I want a function that takes blackBackgroundImage and whiteBackgroundImage and outputs the color and the alpha
I'm bad at math
You're almost there. You just need to solve the system of equations:
Plugging that into the second equation:
So
alpha
should be1 + blackBackgroundImage.r - whiteBackgroundImage.r
. The same applies to any other channel.