Chapter 3 described in detail the use of the GIMP's selection tools; however, that discussion is incomplete. A full understanding of how to effectively work with selections requires a discussion on how to integrate masks. This section shows how masks are complementary to the selection tools and illustrates why the combination of selections and masks is so powerful.
Masks are terrific tools for refining selections. A careful
examination of a mask can often reveal several problems.
Figure 4.36
The resulting channel mask is shown in Figure 4.37(a),
To see the problems associated with the selection, the Zoom tool is used to magnify the image window. This
produces the result shown in Figure 4.38(a).
Figure 4.38(b) shows the same image as in Figure 4.38(a), but with the colors of the mask inverted. The color inversion is done by making the channel mask active and then using the Invert function found in the Image:Image/Colors menu. Inverting the colors inverts the regions of the mask that correspond to selected and unselected pixels in the image. Now it can be seen that in some places, the dark pixels from the subject are showing through around the mask edges. This means that they are mistakenly not included in the set of selected pixels.
Finally, in both Figures 4.38(a) and (b) a rough-edge, aliasing effect can be seen.
Each of these three problems can be solved by refining the mask. This can be accomplished using several different methods, but for this type of fine work near a mask edge, the best choice is the Airbrush tool from the Toolbox. The Airbrush can apply a very light coat of paint, so it is a great touch-up tool. Working near the edge requires some blending of the background with the subject to avoid aliasing. When used with a light pressure the Airbrush is perfect for this.
Figure 4.39(a)
Using the Airbrush tool on the problem pixels shown in
Figure 4.38 produces the results shown in
Figure 4.40.
The previous section showed you how a channel mask could be used to refine a selection. This is so useful that the GIMP has a special pair of function buttons on the image window allowing a selection to be quickly converted to a channel mask and vice versa. These are called the Quick Mask buttons.
Figure 4.41(a)
Figure 4.42
Performing a selection requires separating the subject, the part of the image that interests us, from the background. Often the subject has colorspace features that differentiate it from the background, and the goal of this section is to explain how to exploit this fact. Since the techniques described in this section depend on using an image's natural color features to make the selection, I call this finding the natural mask. The methods are based on using two primary tools: Threshold, found in the Image:Image/Colors menu, and Decompose, found in Image:Image/Mode. The natural mask approach often allows the subject to be extracted in a single, bold operation.
The Threshold tool allows you to specify a range of values in an image. All the pixels that are in the range of the selected values are mapped to white, and the rest are mapped to black. Threshold is a powerful tool for automatically creating masks. This is illustrated in the following example.
Figure 4.43
The Threshold dialog works by clicking and dragging out a part
of the range of values in the histogram. The range of values in the
histogram is in [0,255], and, as can be seen in
Figure 4.44(b),
Toggling the image layer's Eye icon back on allows the channel mask to
be seen over the image, as illustrated in
Figure 4.45.
As shown in Figure 4.45, the result of using Threshold produces an almost perfect mask for the flower. However, several defect regions remain. There are certain parts of the image that should be masked but aren't, and there are parts that are masked but that shouldn't be. These regions are easily removed using the Lasso and the Paintbrush tool.
Figure 4.46(a)
Figure 4.47 shows how the stalk of the flower,
which was not included in the mask, is restored using the Paintbrush tool.
Figure 4.47(a)
For the final step in this example, Figure 4.48(a)
This example shows how using Threshold can produce a selection much more quickly than would have been possible with the Bezier Path tool. Making a Bezier path would have required placing and refining a large number of control points. In contrast, the procedure employed with the Threshold tool required some experimentation with values in the tool's dialog, followed by some rough selections with the Lasso and some painting with the Paintbrush.
A key element to making the Threshold tool work efficiently is finding a reasonable range of values in the tool dialog's histogram. The example used in this section shows that it is not necessary to find a perfect mask. Rather, the goal is to find a mask that separates the subject from the background enough so that tools such as the Lasso and the Paintbrush can be used to easily clean up the defects.
The range of values used to create the mask in this example is shown in Figure 4.44(b). It is important to understand that this result was obtained by using a trial-and-error, experimental approach. Several contiguous regions of the histogram were swept out by the mouse, and, each time, the parts of the image that mapped to white and black were observed. A tip for finding useful regions is to examine the ranges of values supporting the main bumps in the histogram. These are usually associated with major image features, and it is often the case that one of these bumps is the solution to our search. When a reasonable range has been discovered, the data entry boxes can be used to refine the end points of the range.
Although the Threshold tool is not a panacea and isn't guaranteed to work, it is often successful. It is worth trying to apply the Threshold tool before launching into a long selection process with the Bezier Path tool. Some good examples of using Threshold to make selection masks are illustrated in Sections 7.3 and 7.4.
The Magic Wand, presented in Section 3.1.1, is very similar in principle to Threshold but not nearly as effective. As already described, the Magic Wand works by choosing a seed pixel in the image and interactively setting a threshold that controls how many pixels around the seed are included in the selection. Thus, if the value of the pixel at the seed is S, and the value of the threshold is T, then the range of pixel values that are included in the selection is [S-T,S+T].
Now suppose that the range of pixel values that separates the subject from the background is [R1,R2]. To make the Magic Wand work on this image, the threshold must have the value T=(R2-R1)/2 and the seed must have the value S=(R1+R2)/2. The problem, then, is finding a pixel in the subject having the correct seed value that, when experimenting with threshold values, will produce an acceptable result. This is impractical for several reasons, the main difficulty being that there is no way to use the visual feedback from several tries of the Magic Wand to discover a more refined solution.
On the other hand, Threshold requires only that the end points of the range be specified, so it's much better adapted to experimentation. It is easy to try several contiguous value-regions, and the visual feedback from this is very useful for improving the search. In addition, the histogram in the Threshold dialog provides important clues as to which regions may be most useful.
Finally, the algorithm used by the Magic Wand is slow, because for each change in the threshold value, it must recursively grow the selected region around the seed. In comparison, the algorithm for Threshold is very fast, because it must only compare each pixel in the image with a threshold.
In the previous sections, Threshold was applied directly to the image. However, this tool can often be more effective when applied to an image color component. The function Decompose, found in the Image:Image/Mode menu, can be used to separate an image into its RGB and HSV components. When the decomposition is RGB, Decompose creates three grayscale images containing the red, green, and blue channels of the image. For HSV, three grayscales are also created, but now they represent the hue, saturation, and value components of the image. (See Chapter 5 for an in-depth discussion of the relationship between an image and its RGB and HSV color components.)
Figure 4.49(a)
Figure 4.50(a), (b), and (c)