I have a transparent layer in Photoshop CS5 (so internally, it's most probably stored as unpremultiplied RGB component plus an alpha component per pixel).

Now I want to transform this to an opaque layer (just unpremultiplied RGB) + a alpha mask. the result should look the same as the original.

I can't just underlie the transparent layer with black, take the selection from it as a mask and merge the layers, because this would result in the alpha being premultiplied in the RGB values.

I hope you understand the problem and can give me a solution to it.

As an alternative explanation: I want the REVERSE process of this:

  1. create a new layer and paste in any image
  2. create a mask with a white-to-black gradient
  3. apply the layer mask

Explanation images:

State A: enter image description here

State B: enter image description here

IMPORTANT: the layer is just for this example fully constant red - but you could think of any arbitrary image instead of the constant red. so - to go from state A to State B, one simply has to apply the layer mask.

I want to know how to go from State B to State A.

  • I wonder if some type of masking plug-in might help here. The opacity information exists, it's just a matter of how to get it. Getting pixel-level information doesn't exist in the scripting APIs (at least in Applescript, but all of the supported languages seem to align from what I've seen). Mar 10, 2011 at 16:07
  • I believe this will do what you want
    – gman
    Aug 18, 2014 at 19:01

9 Answers 9


I completely understand your pain. Here is my solution :)
Extract Alpha as Mask Action
Here is what it does:

enter image description here Edit:
enter image description here
I hope this helps :)

  • Whoa, cool.. Sure does require use of Actions to make it a bearable process.
    – Ars Magika
    Apr 11, 2011 at 19:48

Wrong! All Wrong!

I fooled myself, and you as well in the process: What I created is indeed a premultiplied image - not premultiplied with black but with white. I leave this answer up for others to build upon it.

I managed to do it like this:

  1. Extract true R-G-B-A channels from image
  2. Use them to build new image

And here's how I did it:

test image

This is the test image i used. The channel view in PS looks like this:


By selecting the individual channels I copied them into individual layers, then flattened them with a white background to recieve a black and white map as shown here:


I also extracted the transparency of the original image into a layer by command-clicking on the layer-thumbnail and filling a new layer with the selection.

Then i created a new image with the same dimensions and without transparency. I then pasted the R-G-B layers I had created into the corresponding channels in the new image:

new image's channels

In the last step, I 'unflattened' the layer by double-clicking, and created a layer mask using the alpha-layer from the original image, resulting in this:

layer mask

As stated above, this doesn't create an un-premultiplied image, as my example would have to look like this to be un-premultiplied:

correct version

Is anyone smarter than me and can create this? I reckon that without advanced pixel-based scripting, this is not possible within Photoshop.


Ok - I created a simple pixelBender filter that can be used with the photoshop PixelBender plugin (http://labs.adobe.com/downloads/pixelbenderplugin.html) to remove the transparency for a layer. here it is: http://neo.cycovery.com/removeTransparency.pbk


I found out how to do it in GIMP it may not be PhotoShop but at least it will do what you ask. (As I interpret it anyway ;) )

  • Open the image in GIMP.
  • Click with your right mousebutton on the layer in the layers box
  • Select "add layer mask" from the context menu
  • In the following menu select "transfer layers alpha channel" and click "add"-button

At this point you're left with an image with an alpha channel mask.

You can go one step further:

  • Right click the layer mask and select "delete layer mask"
  • You're now left with the image without the alpha mask.

There's also a youtube clip on how to do it.

  • Roberto: Yes, you found the answer. That's exactly what we want, and it's free!! I'll use the video you posted as the answer for any other person asking the same (until now only possible by infinitely duplicating the layer in PS)
    – user4481
    May 5, 2012 at 0:57

Based upon the answers given and your comments, the short answer is: you can't do what you want. Once you apply the mask, the layer is rendered and the unseen image data is thrown away.


I made some sample png files and then used php to manipulate them (source code below).

If I create a png with random transparency and save while the layer has a mask, then the 100% clear areas (such as from a box tool) show as white whether alpha support is enabbled or not. Gradients which contain some amount of 100% clear do not show up with alpha disabled.

If I apply the layer mask (permanently) and then create the png, then php serves up the original image if alpha is disabled.

So a potential work-around for this is to find a software package that does not support alpha PNG and resave it from there. As for recovering the original mask, I haven't looked at that yet.

Both code samples are proof-of concept and SLOW.


$im = imagecreatefrompng('./images/alphatest_nolayer.png');
$enable_alpha = 0;  //set to 0 to disable aplha

if ($enable_alpha) {
    imagealphablending($im, false);
    imagesavealpha($im, true);

header('Content-Type: image/png');



To extract the alpha (note: php has a GD limitation of 128 level alpha, rather than 256), so some precision is lost. The alpha can be stretched to 256 using levels tool)


$im = imagecreatefrompng('./images/alphatest_nolayer.png');
$w = imagesx($im);
$h = imagesy($im);

$om = imagecreatetruecolor($w,$h);

for ($x = 0; $x < $w; $x++) {
    for ($y = 0; $y < $h; $y++) {
        $rgb = imagecolorat($im, $x, $y);
        $colors = imagecolorsforindex($im,  $rgb);

        $orgb = imagecolorallocate($om,$colors['alpha'],$colors['alpha'],$colors['alpha']);

header('Content-Type: image/png');


  • but the data is still there. it's the RGB part of the RGBA pixel data. there must be a way to extract it
    – Mat
    Mar 10, 2011 at 18:07
  • 1
    why don't you provide a real-world example file? In your question, you clearly show a single layer with transparent area and no mask, nor indication of an alpha channel.
    – horatio
    Mar 10, 2011 at 18:17
  • .png has a predefined palette color for 100% transparent black, which will propably be used (by photoshop) whenever theres 100% transparency just to save some diskspace.
    – Ars Magika
    Apr 11, 2011 at 19:25
  • Not sure this actually answers the question - seems to be specific to PNG handling.
    – e100
    May 27, 2011 at 16:56

This seems mind-bogglingly complex. If I understand the original question and its various clarifications correctly, the problem is to take any arbitrary image containing transparency and make it fully opaque, then apply the original alpha values as a mask to recreate the original appearance.

If this is the question, the is a very simple answer, if a little tedious.

  1. Copy the layer 10 times. The transparency will "fill in" in the composite image.

  2. Merge all the copies (but NOT the original layer, which you'll need for the last steps).

  3. Repeat steps 1 and 2 with the merged layer, then do it again. At this point, all the pixels that were less than 100% transparent are now 100% opaque (if there are some strays, just repeat the process until there are none). That's as much image information as it's possible to recover.

  4. Ctl/Cmd-Click on the original layer thumbnail to load its transparency.

  5. With the new, opaque layer selected, click the layer mask icon in the Layers Panel.


Ok, this is actually pretty simple (you have to ignore the marching ants)

Make a new layer and fill it entirely with whichever color you're using (if sampling take it from the dead center of the first image)

enter image description here

enter image description here

Then take your first image and CTRL+Click the layer thumbnail, you should see some version of this: enter image description here

As I said before: ignore the marching ants, the feathering comes into effect automatically in CS5.

Then make sure you have the filled layer selected and click the mask button:

enter image description here

Then just hide the bottom layer and you should be done, with the exact effect you're after :)

enter image description here

And that's how to reverse engineer an applied mask in CS5. The CS5 layer selection function is pretty advanced, so most of the time just ignore the marching ants as they don't show correctly any feathering that will go on with the selection :)

Hope it works out for you.

  • thanks for your answer but this is not what i'm looking for - as explained the constant red is just for this example! it can be ANY image (not just a constant fill color) - and of corse i do not have the original untransparent image available
    – Mat
    Mar 10, 2011 at 8:11
  • Well you should post your image in your question. If you post a constant fill, we're going to answer based on a constant fill. Try to use the techniques here though, CS5's selection is very advanced, it may surprise you. It did me.
    – Kyle
    Mar 10, 2011 at 8:13
  • of course i know about those selection techniques! the problem in question is how to access the RGB only part of a transparent layer
    – Mat
    Mar 10, 2011 at 8:14
  • Above the layers there are three tabs, click channels. There you have Red, Green, Blue and Layer Mask. Maybe this is what you're after?
    – Kyle
    Mar 10, 2011 at 8:18
  • but a layer as in neo.cycovery.com/alpha_prob2.jpg does not show an alpha channel - instead it just displays the R G and B channels with transparency already applied
    – Mat
    Mar 10, 2011 at 8:21

What you want to do is easily done by a plugin, like the Photofreebies "Remove Transparency" plugin. First you command-click the layer to select the transparent pixels, then save this transparency information in a new channel to keep it around. Then you apply the "Remove Transparency" filter and you see the 'hidden' pixels in your layer turn opaque (quite interesting to see how Photoshop layouts your 100% transparent pixels BTW). I really wish for years that this was built into Photoshop natively, but alas, too advanced I guess.

Unfortunately, I can't find a Photoshop CS6-compatible version of such a plugin for the Mac, so I'm stuck right now. GraphicConverter can do it too (Remove Alpha channel).


Here's the answer:

  1. Make a layer with the stuff you want in the image.

  2. Make a selection for the desired alpha channel.

  3. Make the selection a "layer mask" for the image layer.

  4. Right click the layer mask and "Apply layer mask".

Now the magic starts:

  1. Go to "Layer", and at the bottom: "Matting", then choose "Remove black matte".

You are welcome!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.