14

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.

9 Answers 9

22

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.

5
  • What version of Photoshop does this apply to? I'm on CS4 but don't see that option. Jun 4, 2012 at 22:50
  • 1
    And it works almost the same way in The Gimp Nov 1, 2012 at 9:00
  • Worked for me in Photoshop CS6
    – macek
    May 16, 2013 at 16:57
  • +1 You can also disable the layer mask to edit the base layer without any transparency and then re-enable it afterwards. (You may also want to unlink the mask while editing the base layer.) These commands are all in the Layer Mask submenu.
    – devios1
    Aug 25, 2014 at 22:12
  • @MichaëlWitrant upvoted because you called it "The Gimp"
    – TKoL
    Jul 6, 2016 at 16:10
2

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

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

1

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!

0

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.

2
  • 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, 2010 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. Nov 10, 2010 at 0:58
0
  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.

0

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

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.

-1

Use levels. turn output levels 0 to 255. add black backlayer.

1
  • Can you explain how to do that? Please do not respond in comments; edit your answer to make it clearer and more complete. Jun 10, 2018 at 15:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .