Nodes/ComfyUI_ZIM/Mask To Bbox (ZIM)
ComfyUI Node

Mask To Bbox (ZIM)

The lazy way to aim the segmenter

By judian17·Created about a year ago·Updated about a year ago· 9
Mask To Bbox (ZIM)
  • mask
  • BBOX

Mask To Bbox (ZIM) is the second helper in the ComfyUI_ZIM pack, and it exists because ZIM Segmenter accepts two kinds of prompt: precise clicks or a rough bounding box. Painting a mask and letting this node derive the box is the low-effort option - you spend five seconds scribbling over the object instead of placing careful points, and the segmenter does the rest. The README is honest that box-prompted segmentation isn't as precise as point-prompted, so treat this as the fast path, not the best path.

It's from the same pack as ZIM Segmenter, so installation is the shared pack install - ComfyUI Manager (search "ComfyUI_ZIM") or:

cd ComfyUI/custom_nodes
git clone https://github.com/judian17/ComfyUI_ZIM

Restart ComfyUI afterward. Like its sibling MaskToPoints, this node is pure OpenCV mask math - no ZIM model involved, no model download, runs instantly. The only heavy dependencies you'll ever install for this pack (zim_anything, onnxruntime-gpu, numpy<=1.26.4) exist to feed ZIM Segmenter itself.

Inputs and output

One input, one output. Give it a mask (MASK), get back a BBOX. Unlike MaskToPoints, which returns one point per white region, this node computes a single bounding rectangle that encompasses all the white areas in the mask - so if your brush strokes covered three separate blobs of an object, you get one box around all of them. The output is the (x, y, width, height) tuple that ZIM Segmenter's bbox input expects.

Plug it in and the segmenter gets its box. That's the whole trick - and it's genuinely handy for batch or automation setups where you want to aim at a subject area without hand-placing coordinates every frame.

How it works and what bites

Mechanically it's the same pipeline as MaskToPoints: threshold the mask to binary, find contours via OpenCV, then take the min/max extents across every contour to build one enclosing box. The two failure modes are shared with its sibling too. It only looks at the first mask in a batch, and an empty mask doesn't error out - it returns (0, 0, 0, 0), which ZIM Segmenter rejects as an invalid bbox and reports as "at least one positive point or a valid bbox must be provided". If you see that and you thought you fed a box in, check whether your mask actually had any white in it.

One nice detail: ZIM Segmenter deliberately accepts several bbox flavors beyond this node's own output - including the ((x, y, w, h),) tuple from MTB-style nodes and xyxy lists from PointsEditor-style ones - so a BBOX produced elsewhere usually slots straight in. All the same, for the intended workflow this node is the native, guaranteed-to-match path. Reach for it when speed beats precision; reach for MaskToPoints when the edge quality actually matters.

CategoryComfyUI_ZIM/mask

Inputs (1)

NameTypeDefaultDescription
maskMASK

Outputs (1)

NameTypeDescription
BBOXBBOX