Nodes/ComfyUI 1hewNodes/Mask Crop by BBox Mask
ComfyUI Node

Mask Crop by BBox Mask

Crop a mask to another mask's bounding box — the clean cutout helper

By 1hew·Created about a year ago·Updated 7 days ago· 33
Mask Crop by BBox Mask
  • mask
  • bbox_mask
  • cropped_mask

Mask-based editing has a rhythm: find the region, crop it, work on it, paste it back. The crop step is where masks usually go off the rails, because cropping an image doesn't automatically crop its mask, and vice versa. Mask Crop by BBox Mask (1hew_MaskCropByBBoxMask) crops a mask to the bounding rectangle of a second mask - so you can cut a region out of a full-scene mask using the same box geometry your image crop used.

The name tells you exactly how to use it: you give it mask (the one you want cropped) and bbox_mask (the one that defines the box), and you get cropped_mask back.

How it works

It finds the minimal rectangle that contains all the white pixels of the bbox_mask (anything above a tiny intensity threshold counts), then crops mask to that rectangle. If the box doesn't overlap the mask, you get the mask back unchanged rather than a crash - the pack's mask nodes are consistently polite about empty regions.

Two details make it batch-friendly. If your mask is a batch, it processes each frame concurrently and cycles the bbox_mask across the batch (so one box can crop N masks). And if the crops come out different sizes - which they will whenever your regions differ - it pads them up to the largest dimensions so the output stays a single stacked tensor instead of a ragged mess.

Inputs and outputs

  • mask - the mask being cropped.
  • bbox_mask - defines the crop box.
  • cropped_mask - the output, cropped and size-normalized.

That's it. No sliders, no modes. This is a utility node and it's comfortable with that.

Installing it

Part of the 1hewNodes pack:

cd ComfyUI/custom_nodes
git clone https://github.com/1hew/ComfyUI-1hewNodes

or via ComfyUI Manager ("1hewNodes"), then restart. No models, no heavy deps.

The natural pair

This node is the mirror of Mask Paste by BBox Mask (also in this pack): crop here, paste there. In a typical inpaint workflow you'd crop the image with the pack's Image Crop With BBox Mask, crop the matching mask with this node so they stay aligned, inpaint or edit the cropped pair at higher resolution, then paste the mask back onto the full canvas. It also pairs with Mask To BBox Mask upstream, which converts any blob into a tight rectangular mask - together they give you "crop to whatever my selection is" without ever typing a coordinate.

Where people get burned: the box comes from the white pixels of the bbox_mask, so if that mask is feathered or fuzzy at the edges, the box is still tight - feathered edges don't move the rectangle much. That's usually what you want. And if you're wondering why your cropped mask isn't the same size as your cropped image, check which bounding boxes each one used; they should be the same mask feeding both nodes. If they are, this node's job is done correctly.

Category1hewNodes/mask

Inputs (2)

NameTypeDefaultDescription
maskMASK
bbox_maskMASK

Outputs (1)

NameTypeDescription
cropped_maskMASK