Nodes/ComfyUI-CustomNodePacks/LocateAnything → SAM Prompt (MEC)
ComfyUI Node

LocateAnything → SAM Prompt (MEC)

The glue that turns grounding boxes into a mask

By Code2Collapse·Created 6 months ago·Updated a day ago· 52
LocateAnything → SAM Prompt (MEC)
  • bboxes
  • image
  • mask
expand_ratio0.05

This node doesn't do anything flashy. It takes a list of bounding boxes and turns them into a filled rectangle mask, padded by a configurable amount. That's it. And that's exactly why you need it - because a grounding model like LocateAnything hands you boxes, and everything downstream in the SAM world wants a mask or a box prompt, not a list.

Think of it as the plumbing between "say it, get boxes" and "box in, mask out." It's the second half of the one-two punch this pack ships: LocateAnything Grounding (MEC) outputs a BBOX_LIST; LocateAnything → SAM Prompt (MEC) eats that list and emits a MASK your SAM nodes understand.

How it works

It's dead simple under the hood: for each box, it fills a rectangle at (x1,y1)→(x2,y2) on a zero canvas sized to your input image. The one knob that matters is expand_ratio (default 0.05, range 0–0.5). It grows every box outward by that fraction of the box's own width and height, which is the classic grounding fix. Grounding models - GroundingDINO, and apparently LocateAnything too - return tight boxes that hug the object. SAM actually prefers a little slack around the subject, and a box that's too tight clips hair, ears, and feet before SAM ever sees it. Set expand_ratio to 0.05–0.1 for humans, a bit more if you keep losing bits of the subject.

Inputs: bboxes (the BBOX_LIST from the grounding node) and image (used to size the mask). Output: a single mask, same resolution as the input image.

Where it goes next

Two standard routes:

  1. Wire the mask into a SAM node's box-prompt input (the pack's SAM Mask Generator, Multi-Mask Picker, or MaskOpsMEC all accept box prompts), and let SAM produce the actual object boundary. This is the smart path - the rectangle is just the prompt; SAM refines it into a clean silhouette.
  2. Use the rectangle directly as a coarse mask for inpainting or compositing, especially if your object is already a neat box (a card, a sign, a screen).

One honest warning: a filled rectangle is not a segmentation. If you run LocateAnything → this node → straight to inpaint, you'll be painting inside a rectangle, not around the subject, and the edges will show it. Go through SAM. The rectangle's whole job is to tell SAM where to look.

Install

Same pack install as its partner:

cd ComfyUI/custom_nodes
git clone https://github.com/Code2Collapse/ComfyUI-CustomNodePacks.git

or ComfyUI Manager → search "CustomNodePacks", then restart and confirm [MEC] Loaded ... in the console. No extra dependencies for this node - it's pure tensor math - but it's useless without the grounding node feeding it, and that one needs transformers plus the multi-GB LocateAnything model. If bboxes is empty or your mask comes back all zeros, check the grounding node's confidence_threshold - you filtered every box out.

CategoryMaskEnhancedControl/Grounding

Inputs (3)

NameTypeDefaultDescription
bboxesBBOX_LIST
imageIMAGE
expand_ratiooptFLOAT0.050–0.5

Outputs (1)

NameTypeDescription
maskMASK