Nodes/comfyui-panels/Unpack BBox
ComfyUI Node

Unpack BBox

Get the Four Numbers Out of a BBOX

By bmad4ever·Created 12 months ago·Updated 2 months ago· 41
Unpack BBox
  • bbox
  • INT
  • INT
  • INT
  • INT

bmad_UnpackBBox is the pack's plumbing: it takes a BBOX and hands back four plain INTs - xmin, ymin, xmax, ymax. Nothing more. It exists because this pack passes bounding boxes around as a single packed value, but the rest of the ComfyUI world often just wants four integers it can shove into a standard crop, region, or sizing node.

Where the BBOX comes from

A BBOX in this pack is a 4-tuple of floats, essentially what polygon.bounds returns for any shapely geometry. You'll get one from a handful of places:

  • Polygon.bounds - turns any polygon into its bounding box (this is the most direct route).
  • Polygon To Resized Mask - its second output is the mask's bbox, so you can unpack that and wire the raw numbers elsewhere.
  • Crop Mask Holes - returns crop boxes alongside its masks and images.
  • BBox from Ints - the reverse of this node, building a BBOX from four integers.

How it works

The node calls unwrap_bbox_as_ints, which rounds the four floats to the nearest integer. One honest caveat: it rounds with Python's round() - it does not floor the min and ceil the max. So a bounding box that starts at x=10.6 comes out as 11, and a bbox that ends at 200.4 comes out as 200. For mask work that's a sub-pixel difference you'll never see; for tight image crops where you're worried about clipping a hair of edge, keep it in mind and pad manually if you're fussy.

The one input and the four outputs

Just bbox - a BBOX. On the other side you get four INT outputs in order: minimum x, minimum y, maximum x, maximum y. The outputs aren't given individual names in the node, so it's on you to remember the order - it's standard xmin, ymin, xmax, ymax, the same order polygon.bounds uses, which at least makes it consistent with the rest of the pack.

Wire the ints into anything that takes plain crop coordinates: standard ComfyUI crop/mask nodes, or other packs' region helpers. If you're building a bridge between this pack's polygon pipeline and some other node suite that doesn't know the BBOX type, this is your adapter.

The trap

Because BBOX is a pack-specific type, don't assume another pack's "BBOX" output is wire-compatible just because it has the same name - ComfyUI matches custom types by string, so a same-named type can connect, but the contents might not be what this node expects. If you get weird results, the safe move is to go through four ints (via this node, or Polygon.bounds (unwrapped), which is the same idea but takes a polygon directly).

Install

Same pack as always. ComfyUI Manager → search comfyui-panels → install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_panels
cd comfyui_panels
pip install -r requirements.txt

Restart ComfyUI and look under Bmad/Panels. Dependencies are shapely, matplotlib, and opencv-python - no models, no VRAM, just numbers.

CategoryBmad/Panels

Inputs (1)

NameTypeDefaultDescription
bboxBBOX

Outputs (4)

NameTypeDescription
INTINT
INTINT
INTINT
INTINT