💀Image SAM2
💀Image SAM2 gives text-prompted segmentation a serious cleanup toolset
- image
- segmented_image
- mask
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_leveltrades 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_paddinga little; SAM2 sometimes masks a hair too tight. - Junk detections - bump
min_box_sizeandquality_threshold, or capmax_detections. - Feathery, soft edges you didn't ask for - set
smooth_strengthto 0 orrefinement_levelto none. - BERT failure - the README's manual
git clone https://huggingface.co/google-bert/bert-base-uncasedintoComfyUI/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.
Inputs (16)
| Name | Type | Default | Description |
|---|---|---|---|
| sam2_model_name | COMBO | sam2.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_name | COMBO | GroundingDINO_SwinT_OGC (694MB) | 2 options: GroundingDINO_SwinT_OGC (694MB), GroundingDINO_SwinB (938MB) |
| image | IMAGE | — | |
| prompt | STRING | object | — |
| threshold | FLOAT | 0.300–1 | — |
| quality_threshold | FLOAT | 0.000–1 | Filter out low-quality segmentations (0 = no filtering) |
| refinement_level | COMBO | standard | Mask refinement quality: none (fastest) to aggressive (best quality) |
| edge_expansion | INT | 0-20–20 | Expand (positive) or shrink (negative) mask edges |
| fill_holes | BOOLEAN | true | Fill small holes in masks |
| remove_small_regions | INT | 1000–1000 | Remove regions smaller than N pixels (0 = disabled) |
| smooth_edges | BOOLEAN | true | Smooth mask edges |
| smooth_strength | FLOAT | 1.00–5 | Edge smoothing strength (0 = sharp, 5 = very soft) |
| max_detections | INT | 00–100 | Maximum number of detection results to output (0 = unlimited) |
| nms_threshold | FLOAT | 0.800–1 | Non-Maximum Suppression threshold for removing overlapping boxes (1.0 = disabled) |
| box_padding | INT | 0-50–50 | Expand (positive) or shrink (negative) detection boxes in pixels |
| min_box_size | INT | 00–500 | Filter out detection boxes smaller than N pixels (0 = disabled) |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| segmented_image | IMAGE | — |
| mask | MASK | — |