Nodes/SimpleSyrup/Prompt SEGS w/ SAM
ComfyUI Node

Prompt SEGS w/ SAM

GroundingDINO finds it, SAM masks it, negative prompts subtract it

By Artificial-Sweetener·Created 3 months ago·Updated 12 days ago· 2
Prompt SEGS w/ SAM
  • image
  • sam_model
  • grounding_dino_model
  • vitmatte_model
  • segs
  • mask
positive_prompt
negative_prompt
confidence_threshold0.30
size_threshold10
keep_only0
keep_byhighest confidence
bbox_dilation0
mask_dilation0
detail_methodGuidedFilter
detail_erode6
detail_dilate6
black_point0.15
white_point0.99
refine_masktrue
mask_refinement_max_size2048
execution_deviceauto
crop_factor3.0
sort_orderlargest to smallest
combine_segsfalse

This is the node people mean when they say "Grounded SAM" in ComfyUI: type "person" or "cat" or "red jacket", and it finds every matching thing in the image, cuts it out along its actual outline, and hands you the regions as SEGS. SimpleSyrup.PromptSEGSWithSAM does that in one node - GroundingDINO does the text-driven detection, SAM turns the boxes into precise masks - and then layers on two things the plain version doesn't give you: a negative prompt, and proper edge refinement.

Why it's the star of the pack's detection cluster: it's the node that turns natural language directly into detailer input. No YOLO weights, no class files. The whole point of text-driven detection is that "find the faces" and "find the logo" and "find the cups on the table" are the same workflow with a different string.

The pipeline, from the tooltips and the source: your positive_prompt goes to GroundingDINO, which returns boxes that score above confidence_threshold (default 0.3). Boxes can be grown or shrunk with bbox_dilation before SAM sees them. SAM generates a mask for each box. Then the negative_prompt is subtracted - regions matching text you don't want get removed from the detected area - and the surviving masks can be dilated (mask_dilation), edge-refined, and trimmed (size_threshold, keep_only / keep_by).

The two parts of this that trip people up, and what to do:

  • Confidence vs. recall. confidence_threshold at 0.3 is a reasonable middle. Raise it toward 0.5 if you're getting junk detections; lower it if you're missing things. GroundingDINO is permissive, so most people tune down, not up.
  • Edge refinement is on by default (refine_mask true, method GuidedFilter, detail_erode 6, detail_dilate 6). This is what keeps your masks from looking like SAM's default wobbly edges. It costs time on big images, hence mask_refinement_max_size (default 2048) bounding the working size, and execution_device (auto vs forcing CPU to dodge GPU memory pressure). If you have a ViTMatte model, the optional vitmatte_model input unlocks VITMatte as a detail_method - the highest-quality edge option, at the cost of another model.

On the output side you get segs and mask. mask is the combined prompted area as a standard ComfyUI mask - that alone is worth the node if you've ever tried to build a "mask everything that's a person" mask by hand. And because these SEGS are Impact-compatible, the regions flow straight into FaceDetailer-style detailing, the pack's regional samplers, or tiled diffusion contexts.

The negative prompt is the sleeper feature. Want "person" but not "person wearing a hat"? That's the difference between detections you have to manually prune and detections that arrive pre-pruned.

Install: the pack:

cd ComfyUI/custom_nodes
git clone https://github.com/Artificial-Sweetener/SimpleSyrup
cd SimpleSyrup && pip install -r requirements.txt

or ComfyUI Manager → search SimpleSyrup → Install → restart, with current ComfyUI (v3 extension API). This node needs a GroundingDINO model and a SAM model - the pack's own Load Ultralytics Model, SAM Model Loader, and a GroundingDINO loader provide them, and the downloadable-models setting can fetch known catalog entries for you. Models are the usual source of "it doesn't work": no detections → check the confidence threshold and that the prompt names something actually in the image; weird mask edges → leave refinement on and stop cranking detail_erode past what the mask needs.

CategorySimpleSyrup/Detection

Inputs (23)

NameTypeDefaultDescription
imageIMAGEImage to search with the text prompt.
sam_modelSAM_MODELSAM model used to create masks for the prompted boxes.
grounding_dino_modelGROUNDING_DINO_MODEL,DINO_MODELGroundingDINO model used to find boxes that match the prompt.
positive_promptSTRINGText describing the regions to detect.
negative_promptSTRINGText describing areas to subtract from the detected regions.
confidence_thresholdFLOAT0.300–1Minimum GroundingDINO confidence required to create a SAM prompt box.
size_thresholdINT101–8192Discard final regions whose mask bounds are smaller than this many pixels wide or tall.
keep_onlyINT00–4096Keep only this many detected regions after threshold filtering. Use 0 to keep all regions.
keep_byCOMBOhighest confidenceChoose how regions are ranked when Keep Only is greater than 0.
bbox_dilationINT0-512–512Grow or shrink prompt boxes in pixels before sending them to SAM.
mask_dilationINT0-512–512Grow or shrink each final region mask in pixels after prompt subtraction.
detail_methodCOMBOGuidedFilterMethod used to refine mask edges.
detail_erodeINT60–255Pixels trimmed inside the mask edge during refinement. Higher values pull the refined edge inward.
detail_dilateINT60–255Pixels added outside the mask edge during refinement. Higher values give refinement more outside context.
black_pointFLOAT0.150–0.98Mask values at or below this become black.
white_pointFLOAT0.990.02–1Mask values at or above this become white.
refine_maskBOOLEANtrueEnable edge refinement for the final masks.
mask_refinement_max_sizeINT20481–16384Maximum working size for mask refinement. Larger images are refined at a bounded size for performance.
execution_deviceCOMBOautoDevice for model-backed refinement. Auto uses normal ComfyUI placement; CPU avoids GPU memory pressure.
crop_factorFLOAT3.01–100How much context to include around each prompted region. Higher values make larger SEG crops.
sort_orderCOMBOlargest to smallestOrder the returned SEGS before output and before the combined mask is built.
combine_segsBOOLEANfalseReturn one unioned SEGS region instead of separate regions.
vitmatte_modeloptVITMATTE_MODELOptional ViTMatte model used when detail_method is VITMatte.

Outputs (2)

NameTypeDescription
segsSEGSPrompted regions as separate or combined SEGS based on combine_segs.
maskMASKCombined prompted area as a standard ComfyUI mask.