Nodes/ComfyUI-Apt_Preset/mask_sam_detctor
ComfyUI Node

mask_sam_detctor

Point, box, or text-prompted SAM masking in ComfyUI

By cardenluo·Created 2 years ago·Updated 22 days ago· 309
mask_sam_detctor
  • image
  • masks
  • bboxes
threshold0.50
refine_iterations2
individual_masksfalse
ckpt_namesam3.1_multiplex_fp16.safetensors
pos
permil_str
ui_positive_coords
ui_negative_coords
ui_bboxes_json

Segment Anything's whole pitch is that you point at (or describe) an object and it hands you back a clean mask, no training required. mask_sam_detctor is cardenluo's ComfyUI-Apt_Preset wrapper around that idea, and unusually for this pack, it supports four different ways to tell it what you want masked in the same node.

What it does

The node's own description (translated from the author's Chinese docstring) lays out the mechanics plainly. You can select an object four different ways - an externally supplied bounding box, a point click, a manually drawn box, or a text prompt - and if more than one is present at once, it picks by priority: external box > point > manual box > text. Text prompts support counting: to select three instances of the same thing, you write boy:3 rather than three separate prompts. There's also permil_str, a batch bounding-box format expressed in per-mille (‰, parts-per-thousand) coordinates - "[[x1, y1, x2, y2], [x1, y1, x2, y2], ...]" - for feeding in several precise boxes programmatically instead of drawing them by hand.

The default checkpoint, sam3.1_multiplex_fp16.safetensors, points at the SAM3 generation of Segment Anything models - the current tier in this space as of 2026, showing up across ComfyUI tooling for text-to-mask work and, per Comfy Org's own guidance, as the recommended mask source for video object-removal pipelines. Take the "3.1 multiplex" naming as this specific checkpoint's own label rather than something independently documented elsewhere; SAM3-family models are new enough that naming conventions across different node packs and checkpoint mirrors aren't fully standardized yet.

threshold controls mask confidence cutoff, refine_iterations runs extra refinement passes on the mask boundary, and individual_masks decides whether multiple detected objects come back as one merged mask or as separate mask outputs.

Inputs and outputs

Required: image, threshold (0–1, default 0.5), refine_iterations (0–5, default 2), individual_masks (boolean). Optional: ckpt_name (SAM checkpoint dropdown), pos (text prompt, multiline), permil_str (batch per-mille box string), ui_positive_coords / ui_negative_coords / ui_bboxes_json (populated by the node's interactive point/box editor rather than typed by hand in normal use).

Outputs: masks (MASK) and bboxes (BOUNDING_BOX). Note this node is flagged as an output node (is_output_node: true), meaning it's built to show you something directly in the UI, not just pass data along - expect an interactive canvas for clicking points or drawing boxes rather than a pure headless detector.

For a first attempt, a single text prompt in pos (something specific, like "boy" or "red car") is the simplest path - get that working before layering in point clicks or manual boxes.

Where this fits

Use this anywhere you need a precise mask around a named object rather than the whole foreground - isolating one person out of several for a targeted edit, masking a specific product in a scene, or feeding per-object masks into inpainting or regional prompting. It's overkill for plain background removal; this pack's Mask_Remove_bg2 is the right tool for a simple foreground/background cutout.

Installing it

ComfyUI Manager: search ComfyUI-Apt_Preset. Manual install:

cd ComfyUI/custom_nodes
git clone https://github.com/cardenluo/ComfyUI-Apt_Preset.git

Run install.bat (Windows) or install requirements.txt yourself, restart ComfyUI. You'll need a SAM checkpoint matching the ckpt_name dropdown available in your models folder; the README doesn't spell out a specific download link for this node's checkpoint the way it does for the face/clothes/body segmentation models, so check the node's dropdown against whatever SAM/SAM2/SAM3 checkpoints you already have installed, or grab one from a source consistent with the filename it's asking for.

Troubleshooting

Check for a pack-wide import failure first if the node's missing entirely - ComfyUI-Apt_Preset is large and there's a documented IMPORT FAILED case for it; check your ComfyUI console at startup.

If ckpt_name shows no options, that's a models-folder problem: confirm a matching SAM checkpoint file is actually present and restart ComfyUI, since checkpoint dropdowns are populated at startup, not live. If your text-prompted mask comes back empty or wrong, remember the priority order - if you've also got a box or point set from a previous run still active in the node's UI state, it'll take priority over your text prompt rather than being ignored, which is an easy thing to trip over if you're switching between input modes on the same node.

CategoryApt_Preset/mask

Inputs (10)

NameTypeDefaultDescription
imageIMAGE
thresholdFLOAT0.500–1
refine_iterationsINT20–5
individual_masksBOOLEANfalse
ckpt_nameoptCOMBOsam3.1_multiplex_fp16.safetensors0 options:
posoptSTRING
permil_stroptSTRING
ui_positive_coordsoptSTRING
ui_negative_coordsoptSTRING
ui_bboxes_jsonoptSTRING

Outputs (2)

NameTypeDescription
masksMASK
bboxesBOUNDING_BOX