🐳遮罩到bbox
Turn a mask into bounding boxes — with a preview so you trust the boxes
- image
- mask
- preview_image
- mask
- bboxes
Automatic detailing lives and dies by bounding boxes. A detector finds a face, returns a box, the detailer zooms into that box and re-renders it - but the detection step doesn't have to come from a fancy model. Sometimes you already have the region as a mask, from SAM, from a segmentation pass, or from your own hand-painted inpaint mask. MaskToBBoxCropper is the bridge: it converts a mask into bounding boxes and draws them on the image so you can see exactly what you're handing downstream.
It ships in 🐳 Pond Nodes (comfy_Pond_Nodes) under 🐳Pond/bbox. The name says "crop," but don't be fooled - it doesn't crop anything. It extracts the boxes. The cropping is somebody else's job.
How it works
The math is old-school OpenCV, no model involved. The mask gets binarized at a 127/255 threshold, findContours locates each separate blob, and boundingRect returns a rectangle per blob. Everything above the threshold counts - so if your mask has three isolated regions (say, two eyes and a mouth), you get three boxes, which is usually what you want for a detailer pass.
The inputs and outputs
Two required inputs, both obvious:
- image - the image the mask belongs to. Used for the preview and as spatial context.
- mask - where the regions are.
Three outputs:
- preview_image - the image with the bounding boxes drawn on it. This is the one you'll actually look at to sanity-check before running anything.
- mask - your original mask, passed through untouched, so you don't lose it.
- bboxes - the boxes themselves, as Pond's own
BBOX_LISTtype. That's the wiring: other nodes in this pack that expect bounding-box input consume this directly, and it's the natural feed into a bbox-driven detailer if the pack you're using speaks the same type.
Installing it
Standard for the pack - Manager search comfy_Pond_Nodes, or:
cd ComfyUI/custom_nodes
git clone https://github.com/Pondowner857/comfy_Pond_Nodes
cd comfy_Pond_Nodes
pip install -r requirements.txt
Restart, then find it under 🐳Pond/bbox. Note this one does need opencv-python, which is in the pack's requirements.txt - the README lists it as required for mask/bbox work, so don't skip the install for this node the way you could for the pure-mask tools. (And yes, the pack's own troubleshooting warns about a console-spam conflict with comfyui_HiDream-Sampler if you happen to have it.)
The gotcha
Because it's a naive threshold-based contour find, noisy masks make noisy boxes. A mask with a speckled, low-confidence edge can split one region into a half-dozen tiny boxes, and a detailer will then run each one as a separate pass. If your boxes come out fragmented, clean the mask first - a bit of blur and a higher threshold upstream beats trying to filter boxes downstream. The preview image is there for exactly this reason: if it looks wrong, fix the mask, not the boxes.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | MASK | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| preview_image | IMAGE | — |
| mask | MASK | — |
| bboxes | BBOX_LIST | — |