ComfyUI Node

Crop Mask by BBox

The small node that keeps your masks aligned with your crops

By Pirog17000·Created about a year ago·Updated 10 months ago· 3
Crop Mask by BBox
  • masks
  • bboxes
  • MASK

If you've ever cropped an image and then tried to use its mask for blending or inpainting, you know the pain: the mask is still full-size, the crop isn't, and now the two are misaligned and you're doing mental coordinate math. Crop Mask by BBox is the fix - it takes your masks and the bounding boxes from a crop operation and slices the mask down to match. It's a tiny node that exists purely to prevent a headache, which is a good reason for a node to exist.

How it works

You feed it masks and bboxes, and it crops each mask using its paired bbox coordinates (x, y, width, height - the same format the pack's crop nodes emit). The output is a MASK list where every mask is now the same size and position as the corresponding cropped image. Nothing clever, nothing magical: it's tensor slicing by bbox, and that's exactly what alignment bugs deserve.

When you need it

This node earns its keep inside the pack's crop-uncrop pipeline. The flow looks like:

  1. Crop From Mask (BatchCropFromMaskSimple) finds the subject region from a mask and returns cropped_images and bboxes.
  2. You process those crops - img2img, upscale, whatever.
  3. Uncrop Image (BatchUncropSimple) pastes the results back using the bboxes.

The gap in that flow: after you process a crop, if you want a mask to go with it - say, to feather the blend or restrict an inpainting pass to the subject - the original mask is still the wrong size. CropMaskByBBox is the bridge. Wire the original mask and the same bboxes in, get a cropped mask back, and everything lines up again.

It's also handy in a more general sense: any time a downstream node hands you (x, y, w, h) coordinates and you have a mask you need to slice, this is the tool.

Installing it

Same pack, same one-time install:

cd ComfyUI/custom_nodes
git clone https://github.com/Pirog17000/Pirogs-Nodes
pip install -r Pirogs-Nodes/requirements.txt

Or ComfyUI Manager → "Pirog's Nodes" → restart. No extra dependencies.

Gotchas

The bbox format matters: it has to be (x, y, width, height), matching the pack's own crop nodes. If you're feeding it bboxes from some other pack that uses a different convention (center-x/center-y, or x1/y1/x2/y2), you'll get nonsense crops with no error to tell you why. Keep the bboxes flowing straight from BatchCropFromMaskSimple and you're safe. Also note it doesn't resize anything - if your bbox is bigger than the mask, the slice just clips, so pair it with the same bbox that made the crop.

Categorypirog/image

Inputs (2)

NameTypeDefaultDescription
masksMASK
bboxesBBOX

Outputs (1)

NameTypeDescription
MASKMASK