π§ Mask Bounding Box
Mask Bounding Box β crop to exactly where the mask is, and get the coordinates
- mask
- image_optional
- MASK
- IMAGE
- x
- y
- width
- height
This is the node that makes "crop to the masked region, fix it, paste it back" actually work. Give Mask Bounding Box a mask and it finds the tightest rectangle that contains the white area, then hands you back not just the cropped mask and image but the exact x, y, width, and height of that box. Those coordinates are the magic - they're what let you put the region back precisely where it came from after you've worked on it.
If you've ever done detail-inpainting the manual way and struggled to line the fixed patch back up, this node is the answer.
What it does
Inputs:
- mask - the
MASKwhose bounding box you want. - padding - extra pixels around the tight box (default 0). A little padding gives an inpaint some context around the subject instead of a claustrophobic tight crop.
- blur - softens the mask edge (default 0), same idea as the feather in Mask Fix.
- image_optional - an optional
IMAGE. Wire your source image here and the node crops it to the same box, so the mask and image stay perfectly aligned.
Outputs, and there are six of them:
- MASK - the cropped mask.
- IMAGE - the cropped image (if you connected one).
- x, y, width, height - the box's position and size as integers.
The workflow it enables
Here's the loop that makes this node worth installing. You've got a full image and a mask of the part you want to redo (a face, a hand, an object). Feed the mask and the image into Mask Bounding Box. It crops both down to just that region - now you inpaint or upscale at full resolution on a small area instead of wasting pixels on the whole frame. When you're done, take the x/y/width/height it gave you and feed them into Image Composite from the same pack to drop the fixed region back into the original at the exact right spot. Clean round trip, no eyeballing the alignment.
This is the modern, content-aware answer to manually typing crop coordinates. Where the old (now deprecated) Crop Image node made you guess x/y/width/height, Mask Bounding Box computes them from your mask.
Installing it
Part of ComfyUI Essentials by cubiq - Matteo Spinelli, the developer behind ComfyUI_IPAdapter_plus:
- ComfyUI Manager: search "ComfyUI Essentials" β Install β restart.
- Manual:
cd ComfyUI/custom_nodes && git clone https://github.com/cubiq/ComfyUI_essentials, installrequirements.txt, restart.
Look for the π§ wrench and the + (MaskBoundingBox+).
Gotchas
Watch padding near the edges. If the masked region is close to the image border, a large padding value can push the box past the edge, and depending on your version you may get a clamped (smaller-than-expected) crop. Keep padding modest if the subject is near the frame edge.
For the paste-back to be pixel-perfect, use the same x/y/width/height this node output - don't recompute or round them elsewhere. That's the whole reason it returns the coordinates.
An empty mask has no bounding box. If nothing's white in the mask, there's nothing to crop to and you'll get an error or a degenerate result - make sure your mask actually contains a region first.
Pack note: cubiq set Essentials to maintenance-only in April 2025. It still works well and this is one of the pack's genuinely valuable nodes, but if it breaks after a big ComfyUI update, roll ComfyUI back or patch it - no upstream fixes. A red "missing node" box means the pack didn't load; check the startup log and reinstall via Manager.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | β | |
| padding | INT | 00β4096 | β |
| blur | INT | 00β256 | β |
| image_optionalopt | IMAGE | β |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | β |
| IMAGE | IMAGE | β |
| x | INT | β |
| y | INT | β |
| width | INT | β |
| height | INT | β |