Nodes/XB_ToolBox/XB-llama - 🎭 BBox转Mask
ComfyUI Node

XB-llama - 🎭 BBox转Mask

Turn LLM-detected boxes into a soft, feathered mask

By wjluoxiao·Created 5 months ago·Updated 6 days ago· 302
XB-llama - 🎭 BBox转Mask
  • bboxes
  • image
  • mask
dilation10
feather0

You asked a vision LLM where the cat is, it gave you boxes, and now you want to actually do something with that - inpaint, edit, or generate around it. XB_llamaBBox2Mask converts a BBOX set into a single combined MASK sized to your image, so the rest of your pipeline can treat your LLM's detection like any other mask source.

This is the "you can get that mask in SO many ways" philosophy from the KB's detailing essay made literal. Detectors are swappable; the mask is what everything downstream cares about. Here, the detector just happens to be a chat model instead of a YOLO.

Inputs

  • bboxes - the BBOX list, typically straight from XB_llamaJSON2BBox.
  • image - used only for dimensions (it defines the mask's width/height). Give it the same image the boxes came from.
  • dilation - how much to grow each box outward, in pixels, default 10. This is the "make the mask bigger than the box" knob, and it matters: a tight box edge on a mask produces visible seams in the final composite, so a little dilation is usually the right call.
  • feather - gaussian blur sigma on the mask, default 0. Turn it up (say 5–15) for a soft-edged mask that blends smoothly into inpainted regions instead of a hard rectangle boundary. Zero gives you a crisp, binary mask.

Output

One mask - a combined MASK where all boxes are unioned together (overlapping boxes just merge). It's a single mask even for many boxes, so it plugs directly into any inpainting or masked-edit node. Wire it into VAE Encode for Inpaint, Set Latent Noise Mask, or a paste-back compositor.

Installing it

Part of XB_ToolBox - ComfyUI Manager (XB_ToolBox) or:

cd ComfyUI/custom_nodes
git clone https://github.com/WJLUOXIAO/XB_ToolBox.git

restart, done. Zero extra dependencies; it's pure tensor math on the mask.

The judgment calls

The two inputs that actually determine quality are dilation and feather, and there's no universal right answer. For inpainting, a mild dilation plus feather 8–15 hides the seam where the model regenerates into the mask edge - the KB's inpainting rules (blur your mask, don't edit right on the boundary) apply unchanged. For hard cropping or region targeting where you want exactly the box, dilation 0 / feather 0 is correct. The trap is feathering a mask you then use to cut pixels out - a feathered mask isn't binary, and a crop node expecting a hard mask will behave oddly. Know which consumer your mask is headed to before you soften it.

One more: since boxes are rectangles, this mask will look like rectangles. If your subject isn't a rectangle (and nothing is), a rectangle mask means the inpaint or detail pass covers background too. That's inherent to bbox detection - the refinement comes from pairing this with a segmentation model downstream, or just accepting the rectangle for quick edits.

CategoryXB-llama

Inputs (4)

NameTypeDefaultDescription
bboxesBBOX
imageIMAGE
dilationINT100–200
featherINT00–100

Outputs (1)

NameTypeDescription
maskMASK