Skip to content

Masking Tool

BitcrushedHeart edited this page Jul 12, 2026 · 5 revisions

Masking Tool

The Masking Tool creates masks for the images in your dataset. A mask marks the region of each image that matters most for training, allowing masked diffusion training to concentrate on the subject and pay less attention to the background.

You can generate masks automatically across a whole folder, generate a mask for a single image from a model, or draw and refine masks by hand. All three approaches save to the same mask file, so you can start with an automatic mask and then tidy it up manually.

Bitcrush Studio Masking Tool

How Masks Are Stored

Each mask is saved as a greyscale PNG next to its image, using the image's filename with a -masklabel.png suffix. For example, a mask for Portraits/subject01.jpg is written to Portraits/subject01-masklabel.png.

The white areas of the mask indicate the region to emphasise, while black areas are treated as background. Training tools that support masked training, such as OneTrainer, read these files automatically when they sit alongside the image.

Note: Studio excludes -masklabel.png files when it scans a folder for images, so masks never appear as separate entries in Gallery View or become captioning targets.

When a mask is created or removed, Studio updates the image's masked state so that folder statistics stay accurate without a full re-scan.

Batch and Draw Modes

The sidebar has two tabs:

  • Batch: Build a list of detections and run them across the current folder, or preview them on a single image.
  • Draw: Edit the mask for the current image by hand, or generate a mask for that image from a single model.

Both modes share the same central canvas and the same navigation controls, so you can move freely between reviewing a batch result and refining it by hand.

Loading an Image

Use Prev, Random, and Next above the canvas to move through the images in the current folder, or use the left and right arrow keys. Studio walks a shuffled order so that every image is shown once before any repeats, and preloads the neighbouring images so stepping through feels immediate.

The current image path and its position within the folder are shown to the right of the navigation buttons.

Batch Masking

The Detection List lets you combine one or more detections. Each detection produces its own mask, and Studio merges them together with a logical OR, so the final mask covers everything any detection found.

Select Add Detection to create an entry, then choose an engine and configure it. You can give each entry a label to keep the list readable.

Engines

Engine What it does
Rembg (background removal) A pre-configured salient-object model that separates the main subject from the background.
Rembg-Human (people) A pre-configured model tuned for masking people.
ClipSeg (text prompt) Segments the image according to a text prompt, such as sky, person, or watermark.
Custom model (BYOM) Runs a detector or segmenter that you supply. See Bring Your Own Model.

The two Rembg engines download their weights automatically the first time you use them. ClipSeg loads automatically and selects a model variant to suit the available VRAM. Both Rembg and BYOM require onnxruntime; when it is not present, those engines are shown as unavailable.

Prompt-driven engines (ClipSeg) show a Prompt field. The Rembg engines are ready to run as they are and need no prompt.

Each engine that produces a probability map exposes a Threshold control, which sets how confident the model must be before a pixel is included in the mask.

Bitcrush Studio Masking Tool detection list

Mask Settings

The Mask Settings section applies to every detection in the run:

  • Expand Mask: Grows or shrinks the mask edge. Positive values expand the mask outwards; negative values pull it inwards.
  • Smoothing: Softens the mask edges.
  • Invert mask: Swaps the masked and unmasked regions.
  • Operation Mode: Controls how a new mask interacts with an existing one:
    • Replace (overwrite): Discards any existing mask and saves the new one.
    • Merge (combine): Adds the new mask to the existing one.
    • Substitute (constrain): Keeps only the parts of the new mask that fall within the existing one.
  • Min Mask Coverage: Skips masks that cover less than the chosen percentage of the image. This helps avoid saving near-empty masks when a detection finds very little. Set it to Off to save every mask.

Running a Batch

Use Preview to run the detections on the current image (or a random one) without saving anything, so you can check your settings before committing.

The Batch Settings section controls the scope of a full run:

  • Include subfolders: Extends the run to images in subfolders of the current folder.
  • Skip images with masks: Leaves images that already have a mask untouched.

Select Start Batch to process the folder. Studio runs the detections in the background and processes smaller images first, so the bulk of a dataset finishes quickly and a few very large images do not hold up progress. You can cancel a running batch from the operations area.

Bring Your Own Model (BYOM)

The Custom model (BYOM) engine runs a detector or segmenter that you supply.

Only ONNX (.onnx) weights are accepted. PyTorch (.pt / .pth) checkpoints are rejected, because loading them can execute arbitrary code; export your model to ONNX first (for example, yolo export format=onnx).

Choose the file with Browse, or type its path directly, then select Validate. Studio loads the model and reports its architecture family, task, and detected class names, or explains why the file cannot be used.

A custom model exposes additional controls:

  • Class filter: A comma-separated list of class names to include. Leave it blank to mask every detected class.
  • Confidence: The minimum detection confidence required for a result to contribute to the mask.
  • Overlap (IoU): How strongly overlapping detections are merged into one, through non-maximum suppression. 0.45 is a common default; lower it if a single object is being detected as several overlapping boxes.

Drawing and Refining Masks

The Draw tab lets you edit the mask for the current image directly on the canvas. This is useful for correcting an automatic mask or for masking images by hand.

Bitcrush Studio Masking Tool draw mode

Manual Tools

Four tools are available, each with a keyboard shortcut:

Tool Shortcut Purpose
Brush B Paint mask regions freehand.
Eraser E Remove parts of the mask.
Polygon P Fill an area enclosed by points you place.
Box X Fill a rectangular region.

The Size slider sets the brush and eraser radius as a percentage of the image. You can also adjust it with the [ and ] keys.

You can zoom with Ctrl and the scroll wheel, pan by holding Alt and dragging, and use the minimap to keep your place while working at a high zoom.

Generating a Mask for the Current Image

The Generate from Model section produces a mask for the image on screen from a single engine, which you can then refine with the manual tools. Choose an engine, supply a prompt or model file if required, and select Generate. The result is saved and shown as the mask overlay.

Saving, Clearing, and Deleting

  • Save: Writes the current mask, combining your brush, eraser, polygon, and box edits into the mask file.
  • Clear: Removes the mask from the canvas without deleting the saved file.
  • Delete Saved Mask: Permanently deletes the saved mask file for the current image. This appears only when a saved mask exists.

The status bar beneath the canvas shows the image dimensions, whether a saved mask exists, and whether you have unsaved edits.

Autosave on Navigation

When you move to another image with the navigation buttons or the arrow keys, Studio saves any unsaved edits first. If a save fails, Studio keeps your edits and stays on the current image so that nothing is lost, and shows a brief warning.

Uploading a Mask

You can also provide a mask made outside Studio by uploading an image file for the current picture. Studio validates the file and saves it as that image's mask, using the same -masklabel.png naming convention.

Masks and Training

Masks give a masked diffusion training run a way to focus its attention. During training, the mask tells the trainer which part of each image to prioritise, so the model spends its capacity on the subject rather than on backgrounds or unwanted elements such as watermarks.

Because masks are stored as ordinary PNG files beside their images, they travel with the dataset and are picked up automatically by training tools that support masked training. Different tools may interpret masks slightly differently, so check the documentation for your chosen training tool before beginning a large run.

Related Pages

  • Gallery View — review and manage the images you are masking.
  • Captioning — pair masks with captions and tags for training.

Bitcrush Studio

Learn how to use Bitcrush Studio here!

Overview

Dataset Management

Patreon Subscribers

Clone this wiki locally