I have an image of a solid-black graphic with anti-aliased edges on a shaded-red background, and an image of the background without the graphic, and I want to recover an image of the graphic without the background. My goal is a solid-black layer with a layer mask that reproduces the original graphic as an all-black image with an Alpha channel.
I can calculate the necessary darkness value K for each pixel of the layer mask with the equation K = round(100 (1 - (C_{BG} - C_{out}) / C_{BG})). However, doing this for each pixel one at a time would be incredibly tedious. Is this something that can be automated with a script?
I have a Photoshop file with the graphic-and-background as Layer 1, the background-without-graphic as Layer 2, and a solid-black layer with a layer mask as Layer 3. I want to have a script that:
- looks at one pixel in the image,
- reads the color of that pixel on Layer 1 and sets that as the variable C_{BG},
- reads the color of that pixel on Layer 2 and sets that as the variable C_{out},
- calculates the variable K = round(100 (1 - (C_{BG} - C_{out}) / C_{BG})),
- sets the darkness value K of that pixel on the layer mask of Layer 3, and
- moves to the next pixel in the image
until it has covered all the pixels.
I know Photoshop supports scripts, but I've never used any, so I don't know how to go about setting one up, or if it's even possible to achieve my goal here.
magick fg.png bg.png -fx "1 - (u[0] - u[1]) / u[1]" out.png