Image editor that allows you to "unstick" an alpha-blended bitmap from its background?

SH
Posted By
Scott H
Jan 22, 2008
Views
290
Replies
1
Status
Closed
Here’s the scenario.

I have two bitmaps. One is the background bitmap, and the other is the same bitmap but with an alpha-blended sprite pasted on it. For my purpose, the alpha-blended sprite is grayscale.

So if

S is the grayscale value of a pixel of the sprite (not known yet), D_r, D_g, D_b are the RGB values of the same pixel of the empty background, and
B_r, B_g, B_b are the RGB values of the finally blended pixel (known beforehand), then

alpha = 1 – (B_r – B_b)/(D_r – D_b)

so that

S = (B_r*(D_r – D_b) – D_r*(B_r – B_b))/(B_r + D_r – B_b – D_b).

So I need an image program that will allow me to do these functional manipulations on the RGB pixel values of separate bitmaps, all at once.

Does Photoshop do it?

Master Retouching Hair

Learn how to rescue details, remove flyaways, add volume, and enhance the definition of hair in any photo. We break down every tool and technique in Photoshop to get picture-perfect hair, every time.

MR
Mike Russell
Jan 23, 2008
"Scott H" wrote in message
Here’s the scenario.

I have two bitmaps. One is the background bitmap, and the other is the same bitmap but with an alpha-blended sprite pasted on it. For my purpose, the alpha-blended sprite is grayscale.

So if

S is the grayscale value of a pixel of the sprite (not known yet), D_r, D_g, D_b are the RGB values of the same pixel of the empty background, and
B_r, B_g, B_b are the RGB values of the finally blended pixel (known beforehand), then

alpha = 1 – (B_r – B_b)/(D_r – D_b)

so that

S = (B_r*(D_r – D_b) – D_r*(B_r – B_b))/(B_r + D_r – B_b – D_b).

I think I see what you’re doing – subtracting the red and blue pixels to get an idea of how much color is in the blended versus unblended pixel. You are then using the ratio of the amount of color to determine the contribution of the gray sprite.

This will work, provided all the background pixels have differing red and blue channel values. Converting the images to HSB space, and comparing saturation values between the blended and background pixels may be a more general way to solve the problem, or you could use logic to determine, on a pixel by pixel basis, which two channels to compare.

So I need an image program that will allow me to do these functional manipulations on the RGB pixel values of separate bitmaps, all at once.

Does Photoshop do it?

Photoshop has a variety of channel calculation functions, including multiply and subtract. I would start by subtracting your blended image from each channel of the background image, and seeing if one of these gives you a reasonable grayscale image. There is a plugin – in the Goodies folder that came with Photoshop – that will convert to HSB space, perhaps for a more stable conversion. You may be able to combine the three results in lighten mode to get a complete grayscale image.

The devil is in the details, though, and in this case it is the transparency. There are situations where the alpha blended pixels will be ambiguous: how do you distinguish a 50% transparent white over black from a solid gray over black? You may have to do something slightly clever, such as interpolate transparency or brightness values from nearby pixels.

If you run into something like this, and Photoshop’s channel ops won’t do the trick, there are at least two higher power guns you can bring out: export it all as a raw file, and use MatLab to do the calculation, or write a small C, VB, or other program to do the calculation.

Mike Russell – www.curvemeister.com

Must-have mockup pack for every graphic designer 🔥🔥🔥

Easy-to-use drag-n-drop Photoshop scene creator with more than 2800 items.

Related Discussion Topics

Nice and short text about related topics in discussion sections