Mask Bounding Box
Turn a mask into crop coordinates
- mask
- x
- y
- width
- height
A small utility node with one job: given a mask, tell you the smallest rectangle that contains everything painted in it. No image processing, no model, just geometry - but it's the piece that turns a hand-painted or auto-generated mask into something you can drive a crop node with.
Why you'd want this
The whole idea behind crop-then-inpaint workflows - crop tight to the region you care about, run your inpaint model or sampler on just that crop at full resolution, then stitch the result back - depends on knowing exactly where to crop. That's what this node computes for you instead of you eyeballing coordinates. It's the kind of node that's invisible when you're using a purpose-built crop-and-stitch node pack, but genuinely useful if you're wiring up a custom crop step by hand, or feeding a downstream node (an upscaler, a detail pass) that wants explicit region bounds rather than a mask.
Inputs and outputs
- mask - the only input.
Four outputs, all plain INT:
- x, y - top-left corner of the bounding box.
- width, height - its dimensions.
That's the whole node. Wire these into an image crop node's coordinate inputs, or into math nodes if you need padding added before you crop.
Installing it
Comes with the rest of the pack - ComfyUI Manager (search "ComfyUI Inpaint Nodes"), or:
cd ComfyUI/custom_nodes
git clone https://github.com/Acly/comfyui-inpaint-nodes.git
Restart ComfyUI afterward. Nothing else to download - this is pure computation, no model involved.
Common issues
An empty mask has no meaningful box. If nothing's actually painted (a fully black mask), there's no real region to bound - make sure whatever produced your mask (manual painting, a detection model, a threshold operation) actually put something non-zero in it before this node runs, or you'll get a degenerate result downstream.
Add your own padding. This node gives you the exact bounds of the mask, not a comfortable margin around it - the same reasoning behind Expand Mask elsewhere in this pack. If you crop to precisely these coordinates, your inpaint model gets zero surrounding context to blend against. Pad the box a bit (a simple math node on width/height, or growing the mask before this node runs) before you actually crop.
Pairs well with Expand Mask upstream and a crop/composite node pack downstream - this node is a connector piece, not a full pipeline on its own.
It's the plumbing behind a pattern you've probably seen described, even if you've never built it yourself. Crop tight to the masked region, run your inpaint model or sampler on just that crop at full resolution, then stitch the result back over the original - that's how a lot of high-detail inpainting gets its quality, because a small region rendered at full generation resolution carries far more detail than the same region would get inside a full-frame pass. Purpose-built crop-and-stitch node packs handle the whole round trip for you, but if you're assembling something custom - feeding coordinates to a specific crop node, or driving conditional logic based on how big the masked region actually is - this is the node that turns your mask into numbers you can work with.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| x | INT | — |
| y | INT | — |
| width | INT | — |
| height | INT | — |