Gifgit
Home > Learn > Layer Masks

Layer Masks

Layer masks are used to apply transparency to specific areas of the image in a layer. You've probably used the eraser tool before to remove parts of an image as shown below. When you use the eraser tool to completely erase parts of an image you are really changing the erased region to 100% transparency. You can use a layer mask to do the same thing as the eraser tool. A layer mask, though achieving the same result as the eraser, operates differently and is way more flexible. It uses a grayscale or black and white image to control the opacity of specific areas in the layer. As you gain a better understanding of layer masks you will see why you will prefer to use them over the eraser tool. First, lets see how a layer mask operates.
eraser tool use
Image coutesy of Pixabay
Fig.1 Image with left portion erased or fully transparent. Note that the checkered background indicates transparency.

How a Layer Mask works

When you hear the word mask you think of the mask covering something. What is the layer mask covering? Well, you can think of the layer mask as covering the image in the layer with transparency information. However, simply saying a layer mask covers a layer with transparency information does not give a full conceptual understanding of how a layer mask works. More completely, a layer mask can be defined as an image that uses the grayscale value of its pixels to map to and change the transparency value of corresponding pixels in the layers image. White in the mask means fully opaque or visible on the other hand black means fully transparent or invisible. Ok, so that may be a little cerebral, lets use a graphical illustration to visualize the operation and use of a layer mask.

Remember in the first paragraph it was mentioned that the same erased image in figure 1 can be achieved with a layer mask? Well lets do it. Firstly, as outlined in the definition of the layer mask, we need the mask to be a black and white image that tells which areas will be transparent and which will be fully visible or opaque. To erase in the image we will make black areas in the mask where the eraser tool would be used. The illustration below shows the grayscale image of the mask above the original unerased photo of the hot air balloon. Applying the mask results in the erased photo of the balloon shown on the right. The black areas in the mask has changed the areas of the image to 100% transparent or 0% opaque. The result is the same as using the eraser tool.
applying layer mask
Image property of Gifgit
Fig.2 Illustrates applying a layer mask to the original image to get the same erased image shown in Fig.1.
Now lets examine the operation of the layer mask at pixel level. Imagine we are viewing a cross section of the layer mask atop the original photo just like the arrangement in figure 2 above. The red square represents a pixel in the mask that is completely black, which means a grayscale value of 0. The pixel in the mask 'masks over' the pixel in the original image represented by the green box. The image editor takes the zero grayscale value of the black pixel and sets the opacity of the corresponding pixel in the image (represented by the green box). This creates a transparent pixel shown by the blue box in the final erased image.
applying layer mask
Image property of Gifgit
Fig.3 The red, green and blue boxes represent pixels in the associated image. The pixel of the layer mask (red square) is used to alter the opacity of the corresponding pixel image (green square). This results in the pixel represented by the blue square in the final image. The pixels are greatly exaggerated for simplification.
Here are some quick pointers about layer masks:
  • A layer mask that is pure white covering the whole image will leave the layers' image unchanged.
  • If you paint in the full white layer mask with black it will erase that part of the image by making it transparent.
  • A layer mask that has full black covering the whole image will make the layers' image transparent.
  • If you paint in the full black layer mask with white it will reaveal that part of the image by making it opaque.
  • Any grayscale value between black and white on the layer mask results in a level of transparency represented by the grayscale value.