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

S

Scott H

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?
 
M

Mike Russell

Scott H said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top