Crop Mask By BBox
The sibling crop that keeps your mask in sync with your image
- mask
- bbox
- MASK
Whenever you crop an image for a panel pipeline, you almost always want the mask cropped the same way - otherwise your inpainting mask and your image stop lining up and the whole regional-generation trick falls apart. Crop Mask By BBox is the exact sibling of Crop Image By BBox: same BBOX input convention, same slicing behavior, but on a MASK instead of an IMAGE.
You'll wire these two side by side constantly: one bbox feeds both, one gives you the pixel crop and the other the matching mask crop, and they stay pixel-aligned by construction. That's the pattern behind per-panel regeneration - crop a panel region, render it at full resolution, paste it back - and it only works because the mask and image were cut from the same coordinates.
How it works
Identical machinery to the image crop, swapped for the mask channel layout: it rounds the bbox to integers, clamps into the mask's dimensions, and slices mask[:, ymin:ymax, xmin:xmax]. Output is a single MASK. No padding, no resizing - a plain rectangular cut, which is exactly what you want when the bbox came from a panel's bounds.
The inputs that matter
mask- the mask to crop.bbox- the(xmin, ymin, xmax, ymax)box, same convention asCrop Image By BBox.
One MASK output.
Installing it
Part of comfyui-panels - Manager, search "comfyui-panels", or:
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_panels
Restart, install deps (shapely, matplotlib, opencv-python), no models.
Where people get burned
Keep the bbox source consistent - a bbox computed on a downscaled preview will crop the wrong region on the full-res mask, and because the node silently clamps rather than erroring, you get a subtly wrong crop instead of a loud failure. And remember this node doesn't resize: if you crop a tiny mask region and upscale the image crop, upscale the mask crop by the same factor (or regenerate the mask at target resolution) or the alignment drifts. The pair's whole value is that image and mask stay in lockstep - don't break that by resizing one and not the other.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| bbox | BBOX | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |