Take the 2-minute tour ×
Graphic Design Stack Exchange is a question and answer site for Graphic Design professionals, students, and enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
    
YOu have transparency you wish to make solid? I think some images would help to explain here. :) –  Kyle Sevenoaks Mar 10 '11 at 7:18
    
i added images as an explanation (can't include them in the thread because i have reputation less than 10) –  Mat Mar 10 '11 at 7:50
    
Thanks for the images Mat, i spent a while researching premultiplied alpha - this seems to make all the difference. I'll see if i can add anything tomorrow when i get back to photoshop. –  JamesHenare Mar 10 '11 at 11:06
2  
A good question and one I've always wondered about. –  e100 Mar 10 '11 at 12:02
    
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). –  Philip Regan Mar 10 '11 at 16:07

8 Answers 8

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 :)

share|improve this answer
    
Whoa, cool.. Sure does require use of Actions to make it a bearable process. –  Ars Magika Apr 11 '11 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:

channels

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:

bw-map

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.

share|improve this answer
    
Welcome to the site! You could post the image-urls as text, so a mod or anyone with rep ≥ 1000 (like me) could edit your post to include images :-) as a matter of fact, if you would've had posted the urls already, you would see the images rather than this comment! –  koiyu Mar 10 '11 at 13:28
    
@koiyu of course, i must've had my stupid-goggles on. thanks! –  Florian Dobler Mar 10 '11 at 13:43
1  
+1. Very clever. –  Philip Regan Mar 10 '11 at 13:54
    
@Philip Regan: not so clever at all: i was totally wrong, see my edit for explanation. –  Florian Dobler Mar 10 '11 at 14:18

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

share|improve this answer

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.

share|improve this answer
    
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 '12 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.

EDIT:

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.

<?php

$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');
imagepng($im);

imagedestroy($im);

?>

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)

<?php

$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']);
        imagesetpixel($om,$x,$y,$orgb);
    }
}

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

imagedestroy($om);
imagedestroy($im);

?>
share|improve this answer
    
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 '11 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 '11 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 '11 at 19:25
    
Not sure this actually answers the question - seems to be specific to PNG handling. –  e100 May 27 '11 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.

share|improve this answer

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.

share|improve this answer
    
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 '11 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 Sevenoaks Mar 10 '11 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 '11 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 Sevenoaks Mar 10 '11 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 '11 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).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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