Mask Editing

Mask Editing

Draw and refine face masks using paint, eraser, and polygon tools for precise blending boundaries.

Introduction

Mask editing is the process of defining exactly which pixels belong to the swapped face region. A mask is a grayscale image where white areas represent the face to be replaced and black areas represent the background that should remain untouched. Clean mask boundaries are critical for natural-looking results.

Recaster provides three manual editing tools -- the Paint tool, the Eraser tool, and the Polygon tool -- that you can combine with the auto-segmentation feature for fast, accurate masking.

Paint Tool

The Paint tool lets you add mask coverage by painting directly on the canvas. Click and drag to paint white areas onto the mask, indicating regions that will be included in the face swap.

Adjusting Brush Size

The brush size determines the width of the painted stroke. You can adjust it in several ways:

  • Use the brush size slider in the Tool Panel on the left side of the editor.
  • Press [ to decrease the brush size or ] to increase it.

Brush Size Strategy

Use a large brush for filling in the center of the face, then switch to a smaller brush for precise work along the jawline, hairline, and around the eyes. This two-pass approach is faster than trying to use a single brush size for everything.

Painting Techniques

For the best results when painting masks:

  • Zoom in when working on edges. Use the scroll wheel to zoom into the area you are refining.
  • Use smooth strokes along the face boundary rather than short, choppy dabs. This produces cleaner edges.
  • Follow the natural contour of the face. The mask should trace along the jawline, around the hairline, and below the chin.
  • Avoid covering hair unless you specifically want the swapped face to include hair from the source. Hair blending is one of the most visible artifacts in a face swap.

Eraser Tool

The Eraser tool removes mask coverage by painting black areas onto the mask. Use it to clean up over-painted regions, remove mask from background areas, or trim edges after auto-segmentation.

The eraser shares the same brush size controls as the paint tool. Press E to quickly switch to the Eraser, then press B to switch back to the Paint brush.

Common Use Cases

  • Removing background bleed -- After auto-segmentation, the mask may extend slightly into the background. Use the eraser to clean these edges.
  • Excluding ears -- In many face swaps, keeping the original ears looks more natural. Erase the mask from the ear regions.
  • Hair boundary cleanup -- The most common refinement task. Erase any mask that covers hair strands that should remain from the destination face.
  • Removing occlusions -- If a hand, microphone, or other object partially covers the face, erase the mask from those areas so the original pixels show through.

Polygon Editing

The Polygon tool lets you define mask regions by placing points that form a closed shape. This is particularly useful for creating precise, geometric mask boundaries that would be difficult to achieve with the brush tool alone.

1

Activate the Polygon tool

Click the Polygon button in the Tool Panel or press P on your keyboard.
2

Place points along the face boundary

Click on the canvas to place polygon vertices. Each click adds a new point connected to the previous one by a straight line.
3

Close the polygon

Click near the first point to close the shape, or double-click to automatically close it. The enclosed area becomes part of the mask.
4

Adjust points

After closing the polygon, you can drag individual points to reposition them. This lets you fine-tune the boundary without starting over.

When to Use Polygons

Polygons are ideal for straight or gently curved boundaries like the jawline and forehead. For complex, organic boundaries like the hairline, the paint and eraser tools are usually faster.

Undo and Redo

Every paint stroke, erase stroke, and polygon edit is recorded in the undo history. You can step backward and forward through your changes at any time:

ActionmacOSWindows / Linux
UndoCmd + ZCtrl + Z
RedoShift + Cmd + ZShift + Ctrl + Z

Undo History Limit

The undo history is kept in memory and cleared when you navigate to a different face. Make sure you are satisfied with your edits before switching faces, as you will not be able to undo changes to a previously edited face after navigating away.

Auto-Save Behavior

The Face Editor automatically saves all changes to the face image file when you:

  • Navigate to a different face in the Face Browser.
  • Close the Face Editor to return to the Face Browser.
  • Close the application.

Both the painted mask data and polygon vertex positions are saved as part of the DFLIMG metadata embedded in the face image file. This means your mask edits travel with the file and are preserved across sessions.

No Manual Save Required

There is no "Save" button in the Face Editor. All changes are persisted automatically. If you want to discard your current edits, use Undo repeatedly before navigating away.

Keyboard Shortcuts

Quick reference for all mask editing shortcuts:

ShortcutAction
BSelect Paint (Brush) tool
ESelect Eraser tool
PSelect Polygon tool
[Decrease brush size
]Increase brush size
Cmd/Ctrl + ZUndo last action
Shift + Cmd/Ctrl + ZRedo last action
Scroll WheelZoom in / out
Middle Mouse DragPan canvas
Space + DragPan canvas (alternative)

Best Practices

Start with Auto-Segmentation

Let the BiSeNet model create a baseline mask, then refine it with manual tools. This is significantly faster than painting the entire mask from scratch.

Work at High Zoom

Zoom in to at least 200% when cleaning up mask edges. Small imperfections that are invisible at low zoom can become obvious in the final merged output.

Focus on Problem Faces

Not every face needs manual editing. Use the Face Browser overlays to spot faces with poor masks, then focus your editing time on those specific frames.

Check Mask Coverage

After editing, toggle the mask overlay in the Face Browser to verify coverage. The mask should cover the entire face region without extending into the background or hair.