Mobile app version of vmapp.org
Login or Join
Annie732

: Transparency to unpremultiplied RGB + Alpha 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).

@Annie732

Posted in: #AdobePhotoshop #Transparency

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:


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




Explanation images:

State A:


State B:




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.

10.09% popularity Vote Up Vote Down


Login to follow query

More posts by @Annie732

9 Comments

Sorted by latest first Latest Oldest Best

 

@Gloria351

Here's the answer:


Make a layer with the stuff you want in the image.
Make a selection for the desired alpha channel.
Make the selection a "layer mask" for the image layer.
Right click the layer mask and "Apply layer mask".


Now the magic starts:


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


You are welcome!

10% popularity Vote Up Vote Down


 

@Jamie315

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

10% popularity Vote Up Vote Down


 

@Kevin459

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.

10% popularity Vote Up Vote Down


 

@Hamm6457569

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.


Copy the layer 10 times. The transparency will "fill in" in the composite image.
Merge all the copies (but NOT the original layer, which you'll need for the last steps).
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.
Ctl/Cmd-Click on the original layer thumbnail to load its transparency.
With the new, opaque layer selected, click the layer mask icon in the Layers Panel.

10% popularity Vote Up Vote Down


 

@Murray976

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


Edit:


I hope this helps :)

10% popularity Vote Up Vote Down


 

@Harper654

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: neo.cycovery.com/removeTransparency.pbk

10% popularity Vote Up Vote Down


 

@Vandalay110

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

?>

10% popularity Vote Up Vote Down


 

@Kimberly620

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:


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


And here's how I did it:



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:



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:





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



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

10% popularity Vote Up Vote Down


 

@Si6392903

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)





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


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:



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



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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme