Nodes/ComfyUI-UniversalRemove/UR Boxes To Mask Batch
ComfyUI Node

UR Boxes To Mask Batch

Detector handed you boxes? This turns them into a mask batch

By fengwk·Created 2 months ago·Updated 2 months ago· 0
UR Boxes To Mask Batch
  • images
  • mask
  • selected_frame
  • preview
boxes_json[]
frame_index0
coordinate_format
broadcast_mode
normalizedfalse
preview_color#FF3B30
preview_opacity0.35

Somewhere between your detector's output and your inpaint model there's a shape mismatch: detectors love to talk in bounding boxes, and inpaint models only speak masks. UR Boxes To Mask Batch is the translator. Feed it an IMAGE frame batch and a JSON list of boxes, and it draws those boxes into a MASK - one mask per frame, aligned to your batch.

It's the simpler sibling of UR Regions To Mask Batch. Where the regions node handles circles, polygons, and keyframe timing, this one is strictly rectangles: hand-boxed removal areas, or bboxes imported from an external tool like a YOLO tracker or a detection script.

How it works

The node parses your boxes_json, converts each box to pixel coordinates on the frame, and fills them white in a mask at the frame you specify. Then a broadcast_mode decides how that single frame's mask covers the whole batch. The parsing is forgiving in a useful way:

  • xyxy - plain arrays like [100, 120, 420, 220], or objects with x1/y1/x2/y2 or left/top/right/bottom.
  • xywh - objects with x/y/w/h (or arrays when the format dropdown is set to xywh).
  • normalized - flip this on and all values are treated as 0–1 fractions of the frame, which is what a lot of tracking tools output.

Boxes that hang off the edge get clamped to the frame instead of erroring.

The inputs that matter

You'll set three of them 90% of the time:

  • boxes_json - the boxes themselves. This is the payload.
  • coordinate_format - xyxy or xywh. Get this wrong and your "mask" will be gloriously wrong shapes. This is the classic gotcha.
  • broadcast_mode - what happens to the other frames: repeat_to_batch puts the same mask on every frame, single_frame_only masks just the one frame at frame_index, and hold_after_frame masks that frame onward. For a static logo or watermark that never moves, repeat_to_batch is the one you want.

frame_index picks which frame the boxes apply to, and preview_color/preview_opacity just style the preview overlay so you can see what you're doing.

The outputs

  • mask - the MASK batch, frame-matched to your images. This is the one that goes downstream.
  • selected_frame - the frame you chose, as an image.
  • preview - that frame with the mask overlaid in your chosen color.

Wire the mask into UR Mask Processor for feathering, then UR Keyframe Prep, and you're on the standard remove path.

Common issues

Coordinate-format mismatch is the #1 footgun, full stop - a xywh box read as xyxy becomes a rectangle with a huge negative extent. Second: normalized boxes fed with the toggle off, or absolute pixels fed with it on, will either draw a speck or a box that covers half the frame. Third, an empty or malformed JSON array doesn't crash - it silently produces an empty mask, so if your mask is mysteriously all black, check that your detector actually returned boxes. And a real subtlety: this node gives you rectangles, which is exactly the "bbox vs segmentation" trade the detailing essay warns about - rectangular masks are the ones most likely to leave visible seams. Fine for watermarks; keep polygon masks in mind for organic shapes.

CategoryUniversal Remove

Inputs (8)

NameTypeDefaultDescription
imagesIMAGE
boxes_jsonSTRING[]
frame_indexINT00–1000000
coordinate_formatCOMBO2 options: xyxy, xywh
broadcast_modeCOMBO3 options: repeat_to_batch, single_frame_only, hold_after_frame
normalizedBOOLEANfalse
preview_colorSTRING#FF3B30
preview_opacityFLOAT0.350–1

Outputs (3)

NameTypeDescription
maskMASK
selected_frameIMAGE
previewIMAGE