Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there any simple way to extract the "baked in" transparency in a layer and turn it into a layer mask in Photoshop? To take a simple example: Let's say that I paint a few strokes with a semi-transparent brush, or paste in a .png-file with an alpha channel. The rgb color values and the alpha value for each pixel are now all contained in the layer-image itself. I would like to be able to edit the alpha values as a layer mask, so that the layer image is solid and contains only the RGB values for each pixel.

Is this possible, and in that case how? Thanks.

EDIT: To clarify - I'm not really after the transparency values in themselves, but in the separation of rgb values and alpha values. That means that the layer must become a solid, opaque image with a mask.

share|improve this question
add comment

8 Answers

This is what I do:

  1. Select the layer with transparency
  2. Click on Menu item Layer, Layer Mask, From Transparency.

The transparency will be converted into a layer mask, that you can manipulate from there.

EDIT: in Photoshop CS5 or later.

share|improve this answer
    
What version of Photoshop does this apply to? I'm on CS4 but don't see that option. –  DuckMaestro Jun 4 '12 at 22:50
    
And it works almost the same way in The Gimp –  Michaël Witrant Nov 1 '12 at 9:00
    
Worked for me in Photoshop CS6 –  macek May 16 '13 at 16:57
add comment

I have improved Mike's solution (Photoshop CS3):

  1. Open/create your image with 'baked in' transparency.
  2. Right click on the layer's icon in the Layers window and select Select Pixels.
  3. Layer menu -> Duplicate Layer
  4. Layer menu -> Merge Visible
  5. Repeat steps 3 and 4 several times until there are no semi-transparent pixels. The selection marquee should still remain.
  6. Layer menu -> Flatten image. You should see the transparency disappear. The selection marquee should still remain.
  7. Right click on the layer in the Layers window and select Layer from Background...
  8. Layer menu -> Layer mask -> Reveal Selection
  9. Done :-)
share|improve this answer
add comment

** EDIT - Nevermind, I see now that this is no better than the first response. **

This can be done in Photoshop.

  1. Duplicate Image
  2. Menu>Image>Adjustments>Curves
  3. Grab the top right corner of the curve and drag it to the bottom right corner- Input 255 should read output 0. This is the inverse of your transparency mask. Click "OK"
  4. Menu>Image>Mode>Grayscale
  5. Flatten Image.
  6. Invert image. This is your mask.
  7. Select all
  8. Copy.
  9. Go back to your original image.
  10. Flatten image
  11. Unlock background
  12. Menu>Layer>Layer Mask>Reveal All
  13. Switch to the new channels palette and select the new mask channel.
  14. Click the "eye" to turn the mask view on.
  15. Paste
  16. click the eye to turn the mask view back off
  17. select the RGB channel again.

Done!

Note that if this is a common problem, it could easily be recorded as an action.

share|improve this answer
add comment

Easier way:

  1. Create a white color overlay on the image layer
  2. Create a black layer below the image

And now it should work!

share|improve this answer
add comment

Ok, I'm not sure this is exactly what you're looking for but it seems close.

  • Open/create your image with 'baked in' transparency.
  • Right click on the layer's icon in the Layers window and select Select Pixels.
  • Layer menu -> Flatten image. You should see the color intensity increase and the transparency disappear. The selection marquee should still remain.
  • Right click on the layer in the Layers window and select Layer from Background...
  • Layer menu -> Layer mask -> Reveal Selection

You should now have an opaque layer with fairly saturated colours and a layer mask creating the transparency.

share|improve this answer
    
Thank you for the answer, but it's not quite what I'm after, as the rgb-values are not going to be the same as before... what I'm after is not the layer mask in it self, but the separation between rgb values and transparency so that they can easily be edited independently. The best way I know is to simply stack A LOT (>1000) of copies of the image on top of each other until even the nearly completely transparent pixels become opaque. Then paste in the transparency (extracted by your or some other method) as a layer mask. –  last-child Nov 9 '10 at 15:30
    
I can't find a better way in Photoshop than the layering method you describe. However, it is possible to save the image to a transparent PNG and then convert it to Netpbm PAM image using Png2pam, which can then be loaded back into Photoshop and you can easily convert the alpha channel to a layer mask. The two caveats are (1) Pngtopam is a command line utility for Linux or Windows/Cygwin and (2) pixels that are entirely transparent may not behave as you expect. If you want me to explain the process, please let me know. –  Mike Fitzpatrick Nov 10 '10 at 0:58
add comment
  1. Make sure you have the Netpbm command line utilities installed. For Windows you'll need to have Cygwin installed and then select/install the netpbm package. For Ubuntu you can install it with the command: sudo apt-get install netpbm
  2. In Photoshop (or similar) convert your image to a PNG file with 24 bit color and transparancy and save as inputfile.png
  3. At the command line run the following command

    pngtopam -alphapam inputfile.png > outputfile.pam
    

  4. Load the PAM file back into Photoshop. You will see that the you have the original RGB values from the original image without any transparency. You may see some rough edges of solid color where there were previously transitions to full transparency in the original image. Don't worry about it for now because the layer mask will fix it.

  5. Convert the background to a layer (Layer menu -> New -> Layer from Background )
  6. Create a selection from the alpha channel (Select menu -> Load Selection and choose Alpha 1 as the Channel)
  7. Convert the selection to a layer mask (Layer menu -> Layer Mask -> Reveal selection)

Done. The image should now look like the original image and you can save it in a more popular file format if you wish.

If the chunky borders of 'pure' color are a problem for you, you can improve them by selecting the layer mask and applying a threshold adjustment (threshold = 2 or 1 if you prefer). After this, flatten the image and then repeat steps 5, 6 and 7.

And if someone could show me how to do this all within Photoshop I'd be very glad to find out how.

share|improve this answer
add comment

Ray's answer is almost correct, but at least in some versions of Photoshop, the items he refers to don't exist. Here's what he was probably trying to say (which I use in versions as old as 5.0.2):

  1. In the “Layers” palette, right-click (Windows) / control-click (Mac) on the thumbnail image of the layer you're interested in.
  2. In the resulting contextual menu, choose “Select Layer Transparency.”
  3. You now have the layer's alpha transparency as a selection, also called a “Quick Mask.”

To turn this quick mask into an editable mask for the layer:

  1. If layer masks are off, select the layer in the “Layers” palette, open the the “Layer” menu, open the “Add Layer Mask” submenu, and choose “Reveal All.”
  2. Alt-click (Windows) / option-click (Mac) a layer mask thumbnail image (there will probably be one empty mask enabled)
  3. Using the selection you created from the layer's transparency before, open the “Edit” menu, choose “Fill…”, use black at 100% opacity, and hit “OK.”
  4. You will now have a duplicate of the layer's original transparency as an editable mask, which works in addition to the layer's original transparency (if you want white space or whatever behind for just the editable mask to reveal over lower layers, store the layer's original transparency in a spare channel or something, merge the layer down into an opaque white/whatever layer, and then put the original transparency back into an editable layer mask.) This mask can manipulate or be applied to the layer's transparency in a variety of ways, as detailed in the “Using layer masks” section of Photoshop's built-in help system.

To instead turn the quick mask into a normal alpha channel:

  1. Edit in quick mask mode, either by pressing the “q” key, or by pressing the button with a circle in a square in the “Tools” palette/bar.
  2. In the “Channels” palette (where the “Quick Mask” channel should be the only one selected,) open the palette's menu and select “Duplicate Channel…”.
  3. Its name is normally unimportant, but you may need to give it a certain name. You may also wish to invert it, depending on what type of alpha channel you want. In any case, hit “OK.”
  4. You now have the layer's transparency as an alpha channel.
share|improve this answer
add comment

photoshop has a nice, simple solution.

Select the layer, go to Layer menu -> Layer Mask -> From Transparency.

The A (alpha) is extracted into a greyscale mask and your layer is now opaque (RGB). Disable the mask to see it.

Apply the mask to combine the A with the RGB again.

share|improve this answer
add comment

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.