Pulling objects out of an image

Slashdot it! Delicious Share on Facebook Tweet! Digg!

Layer Masks

Many image editors think of layer masks as the silver bullet of extraction. The basic idea behind these masks is simple. The user defines an additional channel for each layer. This channel then controls the visibility of the pixels in the layer. In theory, this corresponds to the procedure with the alpha channel. However, Gimp gives greater emphasis to the support for the layer masks since they offer other possibilities as well.

Gimp lets you add one layer mask to each layer whether it is transparent or not. This layer mask addition works via the menu under Layer | Mask | Add layer masks … (Figure 7). Gimp creates a narrow border for both the layer and its mask in the layer dock. The active part is highlighted in white. Clicking on the corresponding preview image toggles the action. As a result, you can look either at the layer itself and how it is influenced by the mask, or the layer mask.

Figure 7: You can recognize layer masks by the double symbol in the layer dock. The active part is highlighted in white.

In the dialog for setting up the mask, you specify how it should look. The standard Gimp mask is pure white. This corresponds to full covering power. You will not see any difference with the layer applied from the original state. With a pure black layer mask on the other hand, you will see nothing at first. By adding white color to the layer mask, you then start to see the objects. The airbrush tool is especially well suited to the task in this mode.

The other possibilities are better suited to special applications. Layer's alpha channel uses the contents of an alpha channel to create the layer masks. Transfer layer's alpha channel works in a similar fashion but reverses the effect. Only the layer masks control the result. If a selection already exists in the image this can be accepted via Selection as a layer mask. Gimp translates the brightness of the image into the covering power of the layer with Grayscale copy of layer . Dark areas disappear; light areas remain visible. The channel option is more interesting. It detects the layer masks from the brightness similarly to the grayscale copy. However it uses the color of the selected channel. This option does not work with all Gimp versions.

Many times, you will want to create a layer mask by itself in order to have complete control over the results. There are many ways of doing this. Often, the current layer can serve as the basis for the mask. You can create a layer copy without a mask and edit it in such a way that, ideally, the motif becomes either completely white or completely black while the environment has the exact opposite color tone. Afterwards, you copy the layer that has been prepared for the mask to the clipboard and activate the mask from the work area.

However, Gimp displays the result in the layer dock in a somewhat confusing way. The floating selection appears as usual above the layer that has a mask. Gimp is able to apply the layer as a layer mask according to your wishes only when it is anchored with the anchor button underneath the layer dock for this layer. Once this is accomplished, there are additional possibilities in the context menu of the layer dock for interacting with the layer mask. For example, you can cause Gimp to display the mask instead of the layer content. You can also temporarily deactivate the mask.

There are many factors that go into the way in which a layer mask is created. Instead of manually converting a layer copy into black and white, you can go to the Desaturate function found in the Color menu. The developer version Gimp 2.9.3 expands the capabilities of this function. Gimp now collects options from earlier versions under Desaturate… in the Desaturate sub menu. Additionally, the user will still find Color gray… , Mono Mixer… (the monochromatic channel mixer) and also a tool labeled Sepia… .

The Levels tool (Figure 8) is a likewise practical method. With it, you can control which parts of an image appear white and which appear black by means of two slider bars. These extreme contrasts in color often help you find edges for the borders of an image. In ideal situations, the Levels tool suffices for tasks like masking an almost white sky. In real life, ideal situations do not occur very often.

Figure 8: The Levels tool creates very hard transitions for masks.

There are other methods available. For example, before resorting to the Levels tool, you can bend the color of an image by using scale curves, found under Colors | Curves … in order to create the desired effect (Figure 9). Alternatively, you can go to the channel mixer under Colors | Components | Channel mixer… , or you can use the representation created using the Levels tool as a basis for manual editing.

Figure 9: Sometimes bold curves suffice to create the essence of the mask.

You can see from Figure 8 that the contours of the sailor stand out sharply from the colors of the environment. This is an optimal situation for removing the head from the surrounding water. However the method is not suitable for all areas of the test image. For example, the sky and the sail are no longer easily separable. Here it is necessary to mask the objects with paths.

Professional image editors on the other hand often use manual tools. There are many of these available and they offer many advantages. You only use black and white for colors. The pay off here is that you can apply processes and smear the colors, perform pencil in and whatever else might be needed. If you are experienced using of brush points, you can use pencil and brush for precision extraction of objects.

Gimp 2.9 has a brush named Angular box 2 [4] that adds a special capability. This is an animated brush point, and it can be recognized by the file extension .gih . The special feature of this brush is that it turns itself following the direction you take when drawing.

Extracting Hairs

Extracting extremely tiny details like individual hairs is an art [6]. The methods described here let you perform this task, albeit with considerable effort. As a rule it is necessary for you to create and adapt the masks for situations involving manual work.

Sometimes though, fine grained extractions are not necessary. There is an online Photoshop tutorial that shows a method that achieves a similar result with less work. With the exception of the key combinations, the steps described in the tutorial also apply to Gimp.

One outstanding issue related to the removal of (half) transparent structures is that the background disappears since light shines through the structures. You have the choice of either incorporating the desired transparent object in front of a completely monochromatic background or manually reworking the spots.

The Channel Version

It may be difficult to overlook the Gimp channels, but it is usually only the experienced user who employs the possibilities they offer.

However, channels offer great capabilities. They underlie the RGB(A) structure of the image by making each individual component available. Since components of an image are involved, the channels have only one dimension consisting of component brightness that exists in addition to the X and Y values. In this way, they are equivalent to very special grayscale images of the original image.

When a situation involves images where the objects and background in one of the channels are easily distinguishable, you should not shy away from using these as a selection (Figure 10). You simply place the desired channel in the layer dock. It will appear there as a new layer that can now be manipulated. As described above, a mask is used for the manipulations.

Figure 10: Individual color channels can also be used as masks.

Buy this article as PDF

Express-Checkout as PDF

Pages: 8

Price $0.99
(incl. VAT)

Buy Ubuntu User

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content