Nodes/ComfyUI_EmAySee_CustomNodes/EmAySee_Multi Mask to BBOX
ComfyUI Node

EmAySee_Multi Mask to BBOX

Get one bounding box around all your masks at once

By EmAySee·Created about a year ago·Updated 4 months ago· 2
EmAySee_Multi Mask to BBOX
  • mask_1
  • mask_2
  • mask_3
  • mask_4
  • mask_5
  • mask_6
  • mask_7
  • mask_8
  • mask_9
  • mask_10
  • bbox
  • x
  • y
  • width
  • height

EmAySee Multi Mask to BBOX looks at up to ten masks, finds the tightest bounding box that contains all of their white pixels, and hands you that box - as a BBOX plus the x, y, width, and height split out as separate INTs.

This is a "feed the detailer" node. Once you have a region defined by masks, the natural next step is to tell a crop or detail/upscale node exactly where that region is. The BBOX output type is the one the Impact Pack's Detailer and Crop nodes speak natively, so this plugs straight into that ecosystem - and the individual x/y/width/height INTs let you wire into anything that wants plain numbers, or feed a CropImageByBBox-style node. It's the "my subject is somewhere in this clump of masks, give me the box around all of it" answer.

How it works

The mechanism is refreshingly direct. Every non-zero pixel across all provided masks is collected, and the node takes the minimum and maximum coordinates over the whole set. The resulting box is the union of every mask's footprint: the leftmost white pixel, topmost, rightmost, bottommost, all combined. width and height are inclusive (max minus min plus one), which is a small detail that matters if you're feeding the numbers into a crop - off-by-one at the edges is a classic crop bug.

Behavior worth knowing:

  • mask_1 is required; mask_2 through mask_10 are optional, so a one-mask call works fine.
  • Masks of different resolutions are accepted; coordinates are taken in each mask's own space, so keep them consistent if the exact numbers matter.
  • If every mask is empty, you get a zero box: [0,0,0,0], with x, y, width, height all 0. No crash - but a 0-width box downstream is a real failure, so check for it.

The inputs that matter

Ten mask ports, one required:

  • mask_1 - the first mask, required.
  • mask_2 through mask_10 - optional; add as many as you have.

Outputs: bbox (BBOX, a list [x, y, width, height]), then x, y, width, height as separate INTs. Wire bbox into Impact-style nodes and the INTs into anything that wants primitives - you get both formats so you don't need an adapter.

Installing it

Part of the EmAySee pack:

# ComfyUI Manager: search "ComfyUI_EmAySee_CustomNodes" and install
# or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/EmAySee/ComfyUI_EmAySee_CustomNodes

Restart ComfyUI. No requirements.txt - this node only needs torch.

Common issues

The all-empty case is the one that bites: an empty set of masks returns a zero box silently, and if you pipe that into a crop you'll get an error or a degenerate result far from the node that caused it. If you're automating, guard against it. Also, the BBOX format here is [x, y, width, height] - that's the Impact Pack convention, but not every pack agrees (some use [x1, y1, x2, y2]), so double-check what your downstream node expects before assuming the list matches. And as with any mask math, small stray white specks on your inputs will inflate the box - clean the masks first if you're getting boxes that are bigger than the subject.

CategoryEmAySee/Masking

Inputs (10)

NameTypeDefaultDescription
mask_1MASK
mask_2optMASK
mask_3optMASK
mask_4optMASK
mask_5optMASK
mask_6optMASK
mask_7optMASK
mask_8optMASK
mask_9optMASK
mask_10optMASK

Outputs (5)

NameTypeDescription
bboxBBOX
xINT
yINT
widthINT
heightINT