How to create an alpha mask from an image?


I want to create an image which I can use as a texture in OpenGL. The image is a jpg that comes in red.

In my OpenGL I want to be able to change the red color to any other color the user selects, for this i thought the best solution was just to discard the rgb channels from the original image and only use the alpha channel of the texture, and the rgb the user selected.

The problem is that even thought I have tried for quite some time, this only seems to work for the edges of the image, not the inner part of the image.

This is the example image:

enter image description here

As it can be seen, there are parts that are in pure red, others that are mixed with white, and complete white parts. I need to have "a png alpha image" in where white represents transparent. This means that complete red will have an alpha of 1.0, complete white an alpha of 0.0 and anything in between an alpha between 0.0-1.0.

In OpenGL I have access to the r,g,b,a channels of the texture. So if anyone has another solution that doesn't use alpha that would help too.


6/4/2014 10:01:00 AM

Accepted Answer

I guess you need something like this:

enter image description here

enter image description here

Where deepest red is 100% black. It is not hard to do. You can experiment a bit more with it by:

  1. Desaturate your image to grayscale

  2. Open Levels and tune it up as you need.

I also have done it as PNG with transparency Please check if this is what you need.

To do it as PNG with transparency and ready for recolor:

  1. Select your layer with image and copy to clipboard. Then create a new mask: enter image description here

  2. Paste your image from clipboard to the mask: enter image description here

  3. Turn off the mask and back to usual RGB channels: enter image description here

  4. Hold Ctrl (Cmd) key and click over little thumb of your mask at Channels palette: enter image description here

  5. Now you can delete the white. Press DEL: enter image description here

To check how it works you can try to recolor it by yourself:

  1. Switch on "Hold transparent pixel": enter image description here

  2. Fill it up with any color: enter image description here

Here is the sample how it looks recolored in different colors: enter image description here

6/4/2014 9:25:00 AM