Nodes/comfyui_cv/CV Masks to BBoxes
ComfyUI Node

CV Masks to BBoxes

One tight bounding box per mask of a MASK batch - the generic bridge from region masks (Connected Components, Labels to Masks, Region Properties + the K-Means Mask Clusters blueprint, Seg Masks, GrabCut) to anything that consumes BOUNDING_BOX: 'OpenCV Crop by BBoxes', 'CV Snap BBoxes', the core 'Draw BBoxes' / 'Crop By Bounding Boxes'. Empty masks are dropped by default; 'valid' says which input rows survived, so the boxes can be realigned with the batch. Empty input yields empty outputs and never raises.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Masks to BBoxes
  • masks
  • bboxes
  • areas
  • valid
  • count
threshold0.50
drop_emptytrue
Categoryimage/CV

Inputs (3)

NameTypeDefaultDescription
masksMASKOne mask per region (MASK batch). A single mask yields a single box around ALL of its white pixels - split it with 'CV Connected Components' first if you want one box per blob.
thresholdoptFLOAT0.500–1Mask values above this count as inside the region. Raise it to ignore a soft/feathered halo.
drop_emptyoptBOOLEANtrueSkip masks with no pixels above the threshold. Turn off to keep the batch rows aligned one-to-one - empty masks then emit a zero-size box at the origin.

Outputs (4)

NameTypeDescription
bboxesBOUNDING_BOXCore BOUNDING_BOX data: per-frame lists of {x, y, width, height} dicts - compatible with Draw BBoxes, Crop By Bounding Boxes, Image Crop, etc.
areasNPARRAY(B,) int32: the pixel count of each region, in the same order as the boxes.
validNPARRAY(N,) bool, one entry per INPUT mask: True where a box was emitted. Use it to realign the boxes with the original batch when drop_empty is on.
countINTNumber of boxes emitted.