Try Pro FREE for 2 weeksGet Started

image-masker-by-class — Masking AI Model

Image Masker by Class turns a segmentation or detection result into a clean black-and-white mask from the class names you pick — pixel-precise for segmentation, box-shaped for detectors. Feeds inpainting. CPU, instant.

Details

  • CategoryMasking
  • Year-1
  • License

Inputs & Outputs

ImageInputimage

Upstream model's output image. For segmentation models (SAM2/SAM3/Maskformer/Segformer/DeepLabV3Plus), this is the colored overlay — its pixels are matched against the per-class colors in the text input to produce a pixel-precise mask. For object detectors (DETR/YOLO), only its width/height are used as the mask canvas size.

TextInputstring

Line-separated metadata from an upstream segmentation or detection model. Each line carries a class label and (depending on the upstream) optional color tuple, score, and bbox — the parser auto-detects the format.

ImageOutputimage

Generated mask image by detected class

Parameters

target_classesstringdefault

Class names (comma-separated)

Comma-separated class names to include in the mask. Must match labels emitted by the upstream model's text output — e.g. the prompt word from SAM3/3.1 ('person' — each line also carries '<prompt>_<n>' and 'object_<n>' aliases, but those name single instances in SAM's listing order, not by size or score, so 'object_0' is not the main subject), 'object_<n>' from SAM2 (no prompt), 'subject' from BiRefNet, 'person' / 'car' from DETR/YOLOS, 'dog' from RF-DETR-Seg (80 COCO classes). Multiple classes (and every instance of a class) are unioned into a single mask unless duplication_handling keeps one instance. Leave empty to mask nothing (typically a mistake).

dilationintegerdefault 0range 0–100advanced

Bbox dilation (0-100 px)

Expand each bbox outward by N pixels. Bbox mode only — used with object detectors to avoid edge artifacts when inpainting (e.g. add 10-20px around a removed object). Has no effect when upstream is a segmentation model (pixel-precise output).

duplication_handlingstringdefault Individualsoptions: Individuals, Merge, Largest, Highest Score, Left Most, +4 moreadvanced

Multi-instance handling

How to handle several matched instances. Keep all: 'Individuals' (default) and 'Merge' — in segmentation (pixel) mode both give the union of every matched instance's pixels; in bbox mode 'Individuals' draws each box and 'Merge' one box around all of them. Keep ONE instance, in both modes: 'Largest' — most mask pixels (segmentation) or largest box (bbox); 'Highest Score' — highest upstream confidence score (SAM2/3/3.1, BiRefNet, RF-DETR-Seg, DETR and YOLOS emit one; with Segformer/DeepLabV3Plus and more than one instance it fails with INVALID_VALUE); 'Left/Top/Right/Bottom/Center Most' — by the instance's box position (segmentation uses the bbox in the upstream text, or the extent of the instance's pixels when the upstream emits none, e.g. RF-DETR-Seg). An instance painted over entirely by later masks on the overlay does not compete. To cut out the main subject when SAM also returns fragments (e.g. neighbours' slivers at the edge of a Crop-Each crop): Segmentation-SAM3.1 (prompt 'person') → this (target_classes 'person', duplication_handling 'Largest') → Masking-Image-Apply-Alpha (the crop on its image port; transparent PNG) or Traditional-Image-Multiply (black background). Do not target 'person_0' for that: SAM's instance order is not by size or score.

Tags

  • mask-creation
  • detection-post-process
  • class-based

Alternatives in Image Masking

All AI models