Nodes/ComfyUI-JK-TextTools/BBox to SAM3 Query
ComfyUI Node

BBox to SAM3 Query

Feed a bounding box into SAM3's selector and get a sharper segmentation

By Nakamura2828·Created 8 months ago·Updated 8 months ago· 0
BBox to SAM3 Query
  • bbox
  • box_sam3
  • point_sam3
  • box_tbg_sam3
  • point_tbg_sam3
width0
height0
prompt_typepositive

BBox to SAM3 Query is an adapter for a specific, modern workflow: you already have a bounding box (from a detector, a mask's bounding box, whatever), and you want to hand it to SAM3 as a prompt so the model segments that region precisely. The node converts your XYWH bbox into the exact query formats SAM3's promptable-selector nodes expect - both the newer SAM3-native format and the TBG SAM3 Selector format.

Quick context on SAM3 itself: it's Facebook's third-generation Segment Anything, released late 2025. It's promptable - you give it a box or a point and it produces a precise segmentation mask, which makes it great for refining rough detections. It runs in ComfyUI through wrapper packs, and it needs a HuggingFace access approval plus the model download. This node doesn't run SAM3 or download anything - it just builds the query JSON that the selector consumes.

How it works

From the bbox [[x, y, width, height]] it computes the XYXY corners (x2 = x + w, etc.) and the center point. Then it emits four outputs:

  • box_sam3 (SAM3_BOXES_PROMPT) - a dict of normalized box coordinates plus label flags. Normalized means 0–1 relative to width/height, which is what the SAM3 native nodes want.
  • point_sam3 (SAM3_POINTS_PROMPT) - the center point, same normalization.
  • box_tbg_sam3 (STRING) - JSON like [{"x1": ..., "y1": ..., "x2": ..., "y2": ...}] for the TBG SAM3 Selector, in absolute pixels.
  • point_tbg_sam3 (STRING) - [{"x": ..., "y": ...}] for the TBG selector.

The prompt_type toggle (positive/negative) flips the label flags - useful if you want to tell SAM3 "this is what I don't want."

The gotcha that will bite you

width and height default to 0. With 0s, the SAM3-native outputs (box_sam3, point_sam3) come back empty - the code only builds normalized coordinates when it has real dimensions. The TBG string outputs work regardless (they're absolute pixels), but if you're wiring the SAM3-native outputs and getting nothing, this is why. Set width/height to the actual image size.

Where it fits

The round-trip loop the pack documents: take an existing mask → Mask to BBox → BBox to SAM3 Query → SAM3 Selector → a refined segmentation of exactly that region. It's iterative refinement - "I found it roughly, now segment it properly."

Inputs and outputs

  • bbox (BBOX) - required, XYWH.
  • width / height (INT, default 0) - needed for the SAM3-native normalized outputs.
  • prompt_type (positive / negative, default positive).

Outputs: box_sam3, point_sam3, box_tbg_sam3, point_tbg_sam3 as described above.

Installing it

It's part of ComfyUI-JK-TextTools: Manager search "JK-TextTools", or

cd ComfyUI/custom_nodes
git clone https://github.com/Nakamura2828/ComfyUI-JK-TextTools.git

Restart ComfyUI. The pack itself adds no models and no runtime deps - but the selector you're feeding is a separate node pack with its own SAM3 model requirements, so budget for that in the workflow you build around it.

CategoryJK-TextTools/bbox

Inputs (4)

NameTypeDefaultDescription
bboxBBOX
widthoptINT00–10000
heightoptINT00–10000
prompt_typeoptCOMBOpositive2 options: positive, negative

Outputs (4)

NameTypeDescription
box_sam3SAM3_BOXES_PROMPT
point_sam3SAM3_POINTS_PROMPT
box_tbg_sam3STRING
point_tbg_sam3STRING