ComfyUI Node

💀Image SAM2

💀Image SAM2 gives text-prompted segmentation a serious cleanup toolset

By S4MUEL-404·Created about a year ago·Updated 10 months ago· 4
💀Image SAM2
  • image
  • segmented_image
  • mask
sam2_model_namesam2.1_hiera_small (200MB)
grounding_dino_model_nameGroundingDINO_SwinT_OGC (694MB)
promptobject
threshold0.30
quality_threshold0.00
refinement_levelstandard
edge_expansion0
fill_holestrue
remove_small_regions100
smooth_edgestrue
smooth_strength1.0
max_detections0
nms_threshold0.80
box_padding0
min_box_size0

SAM2 is the model people actually reach for in 2026, and 💀Image SAM2 is where this pack puts its real effort. Like its sibling 💀Image SAM, it takes a text prompt, finds the object with GroundingDINO, then segments it - but on top of that it stacks a 16-parameter cleanup pipeline: duplicate-detection removal, box padding, minimum-size filtering, hole filling, edge smoothing, and quality gating. If you've ever watched a plain SAM node dump fifteen overlapping cat masks and wondered which one to use, this is the node that answers that.

It's the flagship of the S4Tool-Image pack (v1.5.0 rebuilt it, v1.6.0 ships it), and the parameter bloat is real. The good news: the defaults are sensible, and you can ignore most of the knobs until you need them.

The inputs that matter

Start with the same core as 💀Image SAM: sam2_model_name (8 choices, from sam2.1_hiera_tiny (150MB) up to sam2.1_hiera_large (350MB)), grounding_dino_model_name (SwinT or the beefier SwinB), image, prompt, and threshold (default 0.3). The 2.1-series models are the better bet; the plain sam2_ variants are the earlier release.

Then the cleanup layer, roughly in order of how often you'll touch them:

  • max_detections (0–100, default 0 = unlimited) - cap how many results come back. When GroundingDINO fires on "person" in a crowd, this stops you drowning in masks.
  • nms_threshold (0–1, default 0.8) - Non-Maximum Suppression: overlapping detection boxes get merged, killing duplicates. 1.0 disables it. If you see the same object masked three times, lower this.
  • min_box_size (0–500, default 0) - filter out tiny detections. Set it when "noise" objects keep sneaking in.
  • box_padding (-50 to +50 px) - grow or shrink the detection box around the object. Negative helps when SAM keeps clipping object edges.
  • quality_threshold (0–1, default 0) - drop low-quality segmentations; 0 means no filtering.
  • fill_holes, remove_small_regions, smooth_edges + smooth_strength, edge_expansion, refinement_level (none/light/standard/aggressive) - mask post-processing. The tooltips are the author's own descriptions and they're accurate: refinement_level trades speed for edge quality, smooth_strength (0–5) goes from sharp to feather-soft.

Outputs are segmented_image and mask, same as the SAM node - the cutout and the MASK you route onward.

Install

Same pack, same routine - you install the whole S4Tool-Image pack and get this node:

cd ComfyUI/custom_nodes/
git clone https://github.com/S4MUEL-404/ComfyUI-S4Tool-Image.git
pip install -r ComfyUI-S4Tool-Image/requirements.txt

ComfyUI Manager works too: search "S4Tool-Image" → Install → restart.

And the same BERT gotcha as 💀Image SAM applies - GroundingDINO needs it. Do this once per machine or the node will fail (or stall trying to fetch it at runtime):

cd ComfyUI/models/
git clone https://huggingface.co/google-bert/bert-base-uncased

SAM2 checkpoints auto-download into ComfyUI/models/sam2/ on first use (150–350MB), GroundingDINO into ComfyUI/models/grounding-dino/ (700MB–1GB).

Troubleshooting

  • Duplicate masks for one object - lower nms_threshold (try 0.5).
  • Object edges chopped - raise box_padding a little; SAM2 sometimes masks a hair too tight.
  • Junk detections - bump min_box_size and quality_threshold, or cap max_detections.
  • Feathery, soft edges you didn't ask for - set smooth_strength to 0 or refinement_level to none.
  • BERT failure - the README's manual git clone https://huggingface.co/google-bert/bert-base-uncased into ComfyUI/models/ is the reliable fix.

Verdict: this is the node to start with from this pack if you're doing prompt-driven object selection. The older 💀Image SAM is simpler if you want zero knobs, but SAM2's cleanup layer is what makes the output actually usable without hand-touching masks. Just don't feel obligated to touch all sixteen sliders - most workflows run fine on defaults plus threshold and max_detections.

Category💀S4Tool

Inputs (16)

NameTypeDefaultDescription
sam2_model_nameCOMBOsam2.1_hiera_small (200MB)8 options: sam2.1_hiera_tiny (150MB), sam2.1_hiera_small (200MB), sam2.1_hiera_base_plus (250MB), sam2.1_hiera_large (350MB), sam2_hiera_tiny (150MB), sam2_hiera_small (200MB), +2
grounding_dino_model_nameCOMBOGroundingDINO_SwinT_OGC (694MB)2 options: GroundingDINO_SwinT_OGC (694MB), GroundingDINO_SwinB (938MB)
imageIMAGE
promptSTRINGobject
thresholdFLOAT0.300–1
quality_thresholdFLOAT0.000–1Filter out low-quality segmentations (0 = no filtering)
refinement_levelCOMBOstandardMask refinement quality: none (fastest) to aggressive (best quality)
edge_expansionINT0-20–20Expand (positive) or shrink (negative) mask edges
fill_holesBOOLEANtrueFill small holes in masks
remove_small_regionsINT1000–1000Remove regions smaller than N pixels (0 = disabled)
smooth_edgesBOOLEANtrueSmooth mask edges
smooth_strengthFLOAT1.00–5Edge smoothing strength (0 = sharp, 5 = very soft)
max_detectionsINT00–100Maximum number of detection results to output (0 = unlimited)
nms_thresholdFLOAT0.800–1Non-Maximum Suppression threshold for removing overlapping boxes (1.0 = disabled)
box_paddingINT0-50–50Expand (positive) or shrink (negative) detection boxes in pixels
min_box_sizeINT00–500Filter out detection boxes smaller than N pixels (0 = disabled)

Outputs (2)

NameTypeDescription
segmented_imageIMAGE
maskMASK