next up previous contents index
Next: 4.4 Conversions of Selections, Up: 4. Masks Previous: 4.2 Layer Masks

Subsections

        
4.3 Basic Tools for Working with Channel and Layer Masks

This section discusses techniques for editing channel and layer masks. Although, layer masks are used to edit a layer's alpha channel, and channel masks are used to store and edit selections, these two mask types behave similarly. Thus, the techniques for editing and filtering them can be treated in a somewhat unified manner.

      
4.3.1 Painting Tools

One of the most direct ways to modify masks is with the GIMP's painting tools. The Paintbrush,  Pencil,  Airbrush,  Eraser,  Ink Pen,  Dodge and Burn,  Smudge,  and Bucket Fill  tools can all be used. The versatility of these tools allows masks to be created that could not be duplicated using the selection tools alone. This is one of the reasons why masks are complementary to the selection tools.

Figure 4.17

  
Figure 4.17: Using Painting Tools on a Channel Mask
Figure 4.17

illustrates the use of the Paintbrush tool to edit a channel mask. As can be seen from Figure 4.17(a), the Paintbrush tool has been selected from the Toolbox, and white is the Active Foreground Color. Furthermore, as shown in Figure 4.17(b), a medium hard brush has been selected from the Brush Selection  dialog. Figure 4.17(c) illustrates the Channels dialog, which shows that an active channel mask labeled Butterfly has been created. The mask's color is set to yellow, its opacity is 50%, and its Eye icon is toggled on, which means the the channel mask can be seen in the image window. The effect of the mask in the image window is shown in Figure 4.17(d).

The partial transparency of the mask makes it easy to paint in the image window while following the butterfly's outline. As already noted, the mask acts like digital tracing paper. Some white strokes can be seen in the channel mask thumbnail shown in Figure 4.17(c). These were created by painting with the Paintbrush tool in the image window. Because the channel mask is active, the Paintbrush modifies the mask, not the image layer. However, the effect in the image window is to reveal parts of the image layer, as can be seen in Figure 4.17(d). Regions that have been painted white can be repainted black, which restores the mask. Note that although the mask appears yellow in the image window, it actually remains a grayscale image. For this reason white, black, and grays are the only colors that should be used when painting in channel masks.

      
4.3.2 Selection Tools

Selection tools can also be used to modify masks. Cutting a selection while a mask is active fills the selected region of the mask with the current Active Background Color. Like the painting tools, selections can be used to add or subtract parts of the mask.

Figure 4.18

  
Figure 4.18: Using Selection Tools on a Channel Mask: Addition
Figure 4.18

shows how a selection in the image window can be used to add white pixels to the mask and, consequently, add to the set of selected pixels represented by the mask. Figure 4.18(a) shows that a selection has been made in the image window, and Figure 4.18(b) indicates that it was made using the Bezier Path tool. Figure 4.18(b) also shows that the Active Background Color is white. Cutting the selection while the channel mask is active produces the result shown in Figure 4.18(c). The selected part of the mask has been removed from the image window. Furthermore, the corresponding part of the mask has been changed to white, as can be seen from the mask thumbnail shown in Figure 4.18(d).

Alternatively, Figure 4.19

  
Figure 4.19: Using Selection Tools on a Channel Mask: Subtraction
Figure 4.19

shows how a selection can be used to add black pixels to the mask, thus subtracting from the set of selected pixels represented by the mask. Figure 4.19(a) shows the selection in the image window and, as indicated by Figure 4.19(b), the selection was made using the Rectangle Select tool. Figure 4.19(b) also shows that the Active Background Color is set to black. The result of cutting the selection using C-x is shown in Figure 4.19(c). All the pixels in the interior of the rectangle selection have been filled with black, which results in the removal of these pixels from the set of selected pixels represented by the mask.

      
4.3.3 Gradients

When used in layer and channel masks, gradients are very useful blending tools. Figure 4.20

  
Figure 4.20: Two Images
Figure 4.20

is used to illustrate how two images can be blended together using a gradient in a layer mask. To begin, a new transparent layer is created in the lunar module image (Figure 4.20(a)), and the space shuttle image (Figure 4.20(b)) is copied and pasted into it. The paste actually creates a floating selection that is subsequently positioned and anchored to the transparent layer. The result of the paste is illustrated in Figure 4.21(a),
  
Figure 4.21: Pasting and Positioning the Shuttle Over the Lunar Module
Figure 4.21

and the image's Layers dialog is shown in Figure 4.21(b). It can be seen from the Layers dialog that the space shuttle is in the upper layer and that, in preparation for the next step, a layer mask has been created for it.

The blending of the two layers is performed by constructing a gradient  in the layer mask. The following steps are used to accomplish this:

1.
The layer mask is made active by clicking on its thumbnail in the Layers dialog.
2.
The Gradient tool is chosen from the Toolbox, and the Active Foreground Color and the Active Background Color are set to black and white, respectively.
3.
The Tool Options dialog  is opened by double-clicking on the Gradient icon in the Toolbox, and the Blend option is set to FG to BG (RGB).
4.
The gradient is applied by clicking and dragging in the image window starting at the leftmost edge of the space shuttle layer, and releasing slightly to the left of the left shuttle rocket.
The resulting gradient can be seen in the layer mask's thumbnail, shown in Figure 4.22(b).
  
Figure 4.22: Two Images Blended Using a Gradient in a Layer Mask
Figure 4.22

Several points are worth noting here. First, the gradient is created in the layer mask by clicking and dragging in the image window. The gradient is applied to the layer mask because it was made active in the first step of the preceding procedure. Second, as seen in Figure 4.22(a), the gradient in the layer mask blends the upper layer with the lower one by creating a gradual transition from black to white in the mask. The black pixels of the mask make the upper layer completely transparent. The trend from the dark gray to light gray pixels in the mask gradually blends the upper layer into the lower until the mask is totally white, at which point the upper layer is totally opaque. The width of the blend is controlled by the width of the gradient.

The blend made in Figure 4.22 produces a straight, horizontally varying gradient, but what if a more complicated blending interface is desired? This can be solved using the Mode  menu found in the Brush Selection  dialog. Figure 4.23(a)

  
Figure 4.23: The Brush Selection Dialog and the Mode Menu
Figure 4.23

shows the Brush Selection dialog, and Figure 4.23(b) shows the mode menu's choices.

The Mode menu controls how the paint of the gradient combines with what is already active in the image window (whether that be an image layer, a channel mask, or a layer mask). The Normal mode is the default, and this mode just replaces anything that was in the layer with the paint from the gradient. The other modes combine the paint from the gradient in various ways, which are described in depth in Chapter 5. For the moment, however, let's turn our attention to the Multiply and Screen modes. These modes will permit us to create gradients with tailor-made interfaces. To illustrate this, Figure 4.24(a)

  
Figure 4.24: Using Blending Modes to Combine Gradients
Figure 4.24

shows a horizontally varying gradient created by clicking and dragging with the mouse in the image window, beginning at the tail of the red arrow and releasing at its tip. (Note that the red arrow is just for illustrative purposes and is not part of the image or the gradient.)

Choosing the Multiply  mode from the Brush Selection dialog's Mode menu and applying a second gradient to the first is shown in Figure 4.24(b). The direction of the applied gradient is indicated by the red arrow. If the normal combining mode had been used, the second gradient would have replaced the first. However, setting the blending mode to Multiply has produced a completely different effect. The two gradients have been multiplied together. What does it mean to multiply two gradients? Assigning a value of 0 to black, a value of 1 to white, and proportional values for grays provides us with a definition. This numerical correspondence is used to create a gradient that is the product of the first two. More precise definitions for the blending modes are given in Chapter 5.

Figure 4.24(c) shows the result of using the Screen  mode, applied as shown by the red arrow in the figure. This mode works in a manner similar to Multiply mode. It performs a multiplication, except that it is white that is assigned the value of 0 and black the value of 1. As can be seen in Figure 4.24, the Multiply and Screen blending modes can be used to create custom gradient interfaces. The Multiply mode can be used to make a black pivot around the point of application, and the Screen mode to make a white pivot.

Figure 4.22 shows an example of using a gradient in a layer mask to blend two layers. In the upper part of this figure, the blend seems too abrupt, because the black space of the lunar module image contrasts strongly with the gray-blue sky of the space shuttle launch. This can be softened by making the gradient interface curve around the space shuttle image, letting more of the lunar module's black show through from below. Using the Multiply and Screen blending modes to do this produces the effect shown in Figure 4.25(a).

  
Figure 4.25: Custom Blending in the Upper Portion of the Image by Combining Additional Gradients Using the Multiply and Screen Modes
Figure 4.25

The corresponding curved gradient interface can be seen in the layer mask thumbnail shown in Figure 4.25(b).

Effects similar to what were achieved with Multiply and Screen can be had using two other blending modes: Darken Only and Lighten Only.  The results are a little different from those obtained with Multiply and Screen because these two modes provide more angular, predictable results at the corners of intersection. The result is more like a mitred picture frame than a fluid, smooth transition. Figures 4.26(a), (b), and (c)

  
Figure 4.26: Compare Darken Only and Lighten Only with Multiply and Screen in Figure 4.24
Figure 4.26

illustrates the application of the Darken Only and Lighten Only modes. Compare them with the application of the Multiply and Screen modes, shown in Figure 4.24.

Blending modes are discussed in more detail in Section 5.6. A sophisticated use of gradients and blending modes in layer masks is illustrated in Section 7.3.

     
4.3.4 Transparency as a Tool for Editing Masks

To effectively edit masks, the image layer must be partially visible behind the mask so that it can be used as a guide for editing. The semi-transparency of channel masks was discussed in Section 4.3.1, but how is it done for layer masks?  It is done by using the Opacity slider in the Layers dialog. The following example demonstrates its use.

Figure 4.27

  
Figure 4.27: Image with Two Layers and a Layer Mask
Figure 4.27

illustrates an image consisting of two layers. The Layers dialog shown in Figure 4.27(b) shows that the lower layer is a photo of a woods and the upper layer an image of a fish, on an otherwise transparent layer. The upper layer also has a layer mask, which is to be used to edit the fish image.

The goal is to make parts of the fish transparent to create the illusion that the fish is partially behind some of the trees in the woods. This can be done with the layer mask by painting with black on the desired areas of the mask (see Section 4.3.1) or by cutting away parts of the mask with a selection (see Section 4.3.2). However, to effectively edit the layer mask using either approach, you must be able to see the outline of the trees through the fish. This is achieved by making the Fish layer active and, then, lowering the value of the Opacity slider.

Figure 4.28(a)

  
Figure 4.28: Decreasing the Opacity of the Top Layer and the Selection Obtained Using the Bezier Path Tool
Figure 4.28

illustrates the effect of lowering the Fish layer's opacity. Because the trees can be perceived through the fish, it is easy now to edit the layer mask to achieve the desired effect. The result of using the Bezier Path tool to make a selection is shown in Figure 4.28(b) (note that the opacity of the Fish layer has been reset to 100%).

Making sure that the Active Background Color in the Toolbox is set to black and that the layer mask is active in the Layers dialog, the selection is cut by typing C-x in the image window. The result on the image is shown in Figure 4.29(a),

  
Figure 4.29: The Result of Editing the Layer Mask
Figure 4.29

and the thumbnail of the resulting mask can be seen in Figure 4.29(b).

      
4.3.5 Blurring of Masks and Other Effects

Section 3.1.2 discussed an edge-softening technique called antialiasing  and an edge-blending technique called feathering. Effects similar to antialiasing and feathering can be had by applying blur filters to masks.

White pixels in a mask correspond to selected pixels in an image layer, and black pixels in the mask correspond to unselected image pixels. If there are no gray pixels between the black and white zones, this gives the selection edges represented by the mask the harsh edge already seen in the discussion on antialiasing. Blurring a mask softens the sharp edges in the mask by creating a graded zone of gray between the regions of black and white pixels. The width of the gray zone is controlled by the blur radius. The gray zones correspond to partially selected pixels in the image layer, and this is what creates the antialiasing/feathering effect for masks.

Figure 4.30

  
Figure 4.30: An Image and a Mask
Figure 4.30

is used to illustrate the use of blur filters on masks. Figure 4.30(a) shows an image of a wood duck, and Figure 4.30(b) shows a channel mask representing a selection of it. Figure 4.30(c) shows the associated Channels dialog.

A closer examination of the wood duck mask is shown in Figure 4.31(a).

  
Figure 4.31: Aliased Mask Edge Softened Using Blur Filter
Figure 4.31

As can be seen, the mask has an unpleasant, hard, and aliased edge. This can be softened by blurring the mask. Figure 4.31(c) shows the result of applying the Gaussian Blur (IIR)  filter to the mask. The filter dialog is displayed in Figure 4.31(b), which shows the choice of blur radius. In general, a small radius produces an antialiasing effect, and a large blur radius creates a feathering effect. A blur radius of 1 was used for this example.

Other interesting and artistic edge effects can be obtained by processing masks with one or more of the GIMP's large collection of filters, found in the Image:Filters menu. Figures 4.32, 4.33, and 4.34 illustrate some examples.

Figures 4.32(a)

  
Figure 4.32: Applying the Waves Filter to the Wood Duck Mask
Figure 4.32

illustrates the Waves   filter dialog, found in the Image:Filters/Distorts menu. The resulting effect on the wood duck mask is shown in Figures 4.32(b), and the result of applying this mask as a selection to cut away the image's background is shown in Figures 4.32(c). Figure 4.33(a)
  
Figure 4.33: Applying the Glass Tile Filter to the Wood Duck Mask
Figure 4.33

shows the Glass Tile   filter dialog, found in the Image:Filters/Glass Effects menu. Figures 4.33(b) and (c) show the effect of this filter on the mask and the image. Figure 4.34(a)
  
Figure 4.34: Applying the Spread Filter to the Wood Duck Mask
Figure 4.34

shows the Spread   filter dialog, found in the Image:Filters/Noise menu. Figures 4.34(b) and (c) show the effect of this filter on the mask and the image.

Many other interesting filter possibilities can be found. Have fun! Experiment!


next up previous contents index
Next: 4.4 Conversions of Selections, Up: 4. Masks Previous: 4.2 Layer Masks

©2000 Gimp-Savvy.com