2.8. Forgrundsmarkering

Figur 14.33. The Foreground Select tool in the Toolbox

The “Foreground Select” tool in the Toolbox

This tool lets you extract the foreground from the active layer or from a selection. With GIMP-2.10, selection refinement has been improved. After the selection is made, with its marching ants, you can copy-paste or click-and-drag it to another image used as background, and, inverting the selection, you can make changes in background.

2.8.1. Activating the Tool

You can activate the Foreground Select tool in two ways:

  • by clicking on the tool icon in the Toolbox,

  • through ToolsSelection ToolsForeground Select in the image menu.

  • This tool has no shortcut, but you can set one using EditKeyboard Shortcuts, open the Tools group on the left, select Foreground Select and then press the keys you want to use as shortcut.

2.8.2. Directions for use

Let us start with an object that is easy to distinguish from the background and doesn't need to be refined.

[Advarsel] Advarsel

The foreground select tool needs a lot of memory for its processing, depending on the size of the image. It is known to crash or slow down when using larger images.

One way to improve this is to use Matting Global instead of Matting Levin. The slow processing speed can be improved by increasing the number of downsampled Levels, at the cost of using more memory. Both of these options also come with the disadvantage of being less accurate.

  1. The way it works is similar to the Free Select tool. Roughly select the object you want to extract, with a little bit of background around it. To get a more accurate outline, keep the mouse button pressed while moving. To use straight lines for parts of your selection, click and release the button between the start and end points of the straight section.

    As soon you click to start drawing the selection, a small window pops up:

    Before the selection is finished, only the close button x is active, allowing you to cancel and return to the original image (this can also be done by pressing the Esc key).

    To finish the initial selection, it needs to be closed. When the mouse cursor hovers over the dot where you started the selection, it turns yellow. Click this to close the selection. Instead of doing that, you can also double-click to close the selection.

    The selection is closed.

  2. To create the mask from your selection, press Enter, or double-click inside the selection:

    The mouse pointer now changes into a Paintbrush icon with a circle. The dark blue area (this color can be changed) shows the background. The lighter area covers the zone you have selected as foreground and a small part of background. Outside the selected area, the dark blue area is called the Unknown pixels area.

    The options in the small window on top of the image become active:

    • A Preview mask checkbox that toggles displaying a preview of the foreground extraction status. The same can also be done by pressing the Enter key.

    • A Select button that will be used to create the extraction after marking the foreground.

  3. Now we start the actual foreground extraction process: draw a line through the foreground. The size of the brush can be changed in the Tool Options area. Draw a continuous line over the selected foreground area moving over colors which will be kept for the extraction. The color used to draw the line is not important, but not using the same color as the foreground makes it easier to see. Be careful not to paint background pixels.

    With this one-color object, that is easy to distinguish from the background, a few strokes are enough:

  4. Toggle the preview button, or press Enter to verify the result.

    [Bemærk] Bemærk

    You can draw directly on this Preview mask and see the result immediately.

  5. When you are satisfied with the result, click the Select button, or press Enter to finalize the selection and finish the foreground selection operation. You can cancel the operation by pressing Esc.

2.8.3. Indstillinger

Figur 14.34. Foreground Select tool options

“Foreground Select” tool options

Normalt vises værktøjsindstillingerne i et vindue under værktøjskassen, så snart du aktiverer et værktøj. Hvis de ikke gør, kan du få adgang til dem fra billedmenulinjen via VinduerDokbare vinduerVærktøjsindstillinger, som åbner indstillingsvinduet for det valgte værktøj.

Mode; Feather edges
[Bemærk] Bemærk

See Selection Tools Options for help with options that are common to all these tools. Only options that are specific to this tool are explained here.

Draw mode

Draw foreground: when selecting with a brush, what you draw will be considered part of the foreground, i.e. included in the selection.

Draw background: when selecting with a brush, what you draw will be considered part of the background, i.e. it will be excluded from the selection.

Draw unknown: When drawing on the background, outside the initial selection, it marks the drawn pixels as belonging to the foreground.

Stroke width

The size of the brush to select with.

Preview mode
  • Color (default): the color of the selection preview mask; the current color is shown in the color swatch. You can change the color by clicking on it.

  • Grayscale: allows you to see the resulting mask in black and white. This preview is similar to a layer mask. It can be useful in images where foreground and background color are similar and difficult to distinguish. Available since GIMP 2.10.14.

Engine

This is the method that will be used to select the foreground. The default is Matting Levin, which usually gives the best results, but you can also try Matting global, especially if processing is slow and you are using larger images.

Levels (Matting Levin only)

The number of downsampled levels to use. Higher numbers can improve processing speed at the cost of using more memory. The default is 2 levels.

Active levels (Matting Levin only)

The number of levels to perform solving. Higher numbers can increase the selection a bit at the cost of slowing down processing. Setting this number higher than Levels has no effect. The default is 2 active levels.

Iterations (Matting Global only)

Higher values may improve the result at the cost of being slower. The default is 2 iterations.

2.8.4. Refining Foreground Extraction

In a lot of images, distinguishing what is foreground or background can be difficult. Refining the selection allows you to extract these foregrounds. The procedure steps are the same as above, but, while drawing the foreground, you will often toggle Preview, use Zoom (+ key), switch to Draw background to delete unwanted background areas, and switch between Grayscale and Color preview mode.

Figur 14.35. Draw background Example

“Draw background” Example

On the left: drawing foreground by mistake went over the background area: a part of the background will be included in the foreground selection!

In the middle: Draw background option is checked: draw on the unwanted background pixels.

On the right: unwanted selected pixels in the background are no longer in the foreground selection.


Figur 14.36. Draw unknown Example

“Draw unknown” Example

On the left: the selection left a small part of the foreground unselected, in the unknown pixels area.

On the right: with Draw unknown option checked, draw on the unselected pixels to select them. This shows that they are now selected.