How to Use Matting Levin in GIMP

GIMP’s Foreground Select Tool includes the Matting Levin algorithm, a specialized matting engine designed to extract complex subjects like hair, fur, and semi-transparent objects from intricate backgrounds. This guide outlines how to select the Matting Levin engine, paint strokes to define your subject, and extract a clean foreground mask directly in GIMP.

Step 1: Open Your Image and Activate the Tool

  1. Open your image in GIMP by navigating to File > Open.
  2. Select the Foreground Select Tool from the Toolbox, or navigate to Tools > Selection Tools > Foreground Select.

Step 2: Create the Initial Rough Selection

  1. Click and drag your mouse around the subject you want to extract to create a rough boundary enclosing the subject.
  2. Close the loop around the subject and press Enter. A colored overlay (usually dark blue) will cover the unselected background area.

Step 3: Switch the Engine to Matting Levin

  1. Look at the Tool Options panel on the side of your workspace.
  2. Find the Engine dropdown menu.
  3. Select Matting Levin from the list (the default is often set to Matting Global).
  4. Optionally, adjust the Levels and Active Levels settings to balance extraction accuracy and processing performance.

Step 4: Mark Foreground and Background Areas

  1. Ensure the Draw foreground radio button is selected in the Tool Options.
  2. Use the brush to paint a continuous stroke across the main body of the subject you wish to keep. You do not need to cover the entire subject—focus on covering the dominant colors and core areas.
  3. If the background contains complex areas close to the edges, switch to Draw background in the Tool Options and paint over those background sections.
  4. If you need to refine semi-transparent edges, select Draw unknown and paint directly over the ambiguous boundaries (such as fine strands of hair).

Step 5: Preview and Generate the Selection

  1. Check the Preview mask box in the Tool Options dialog to see how the Matting Levin algorithm processes the edges.
  2. If edges are missing or background elements are included, paint additional foreground or background strokes until the preview is accurate.
  3. Once satisfied with the matte, press Enter or click the Select button in the floating dialog.
  4. GIMP will convert the matte into an active selection boundary (marching ants).

Step 6: Isolate the Foreground

  1. Copy the selection using Ctrl + C (Windows/Linux) or Cmd + C (macOS) and paste it into a new layer.
  2. Alternatively, go to Layer > Mask > Add Layer Mask, choose Selection, and click Add to apply the extraction non-destructively.