Nodes/ComfyUI/Crop Mask
ComfyUI Node Runs on cloud

Crop Mask

Cut a region out of a mask, the honest way

By Comfy-Org·Created 4 years ago·Updated about 17 hours ago· 130,493
Crop Mask
  • mask
  • MASK
x0
y0
width512
height512

Crop Mask slices a rectangular region out of a mask and returns just that piece. It's the mask equivalent of cropping an image, and it does exactly what you'd expect: x, y, width, height, and you get back the mask confined to that box. Simple enough to feel pointless - until you realize how much of professional-looking work is "cut out the region, work on it in isolation, put it back."

Why you'll reach for it

The whole crop-and-stitch philosophy lives here. The most reliable inpainting recipe in the community - the crop-edit-stitch pattern - starts by isolating a small region so you can render it at native resolution, and the mask side of that isolation is Crop Mask. Detail work is the big case: a face at 64 pixels in a 1024 frame deserves its own pass at full resolution, and the mask for that pass is a crop of the full-frame face mask.

It's also how you build regional workflows. Segment a person, crop the mask to the face, run a face detailer that only sees that region. Crop the mask to the hand, give the hand a dedicated inpaint. Every "fix just this part" workflow is a crop, a pass, and a stitch - and Crop Mask is the crop.

How it works

The mechanism is a plain tensor slice: mask[:, y:y+height, x:x+width]. No resampling, no interpolation, no smoothing - you get the exact pixels in that box, at the same resolution. What you crop, you get back faithfully, and what's outside the box is simply gone. That purity is the reason it pairs so well with compositing: because nothing was resampled, the cropped mask lines up pixel-for-pixel with a crop of the matching image.

The inputs and outputs

  • mask - the mask to crop from.
  • x, y - top-left corner of the crop, in pixels.
  • width, height - size of the crop.

One output, MASK.

Getting it

Core ComfyUI, nothing to install. It's in comfy_extras/nodes_mask.py with the rest of the mask family, and it's been there since masks existed.

Where people get burned

  • No bounds checking. The node is a raw slice, so x + width past the mask's edge throws an error or returns a ragged result. Keep the crop inside the mask, or clamp the coordinates before you send them. If your values come from a detector, pad them defensively.
  • It crops, it doesn't resize. People expect a crop to also scale the region up to working resolution. That's a separate step (and usually a good one - crop, upscale, work, downscale, stitch). Crop Mask alone just trims.
  • You have to remember the stitch. A crop removes context, and a removed context mask feeds a model that has no idea where the region sits in the frame. For anything where placement matters, plan the composite back before you ever crop - the KB's best practice is that a workflow which skips compositing turns to trash within a few passes.
Categoryimage/mask

Inputs (5)

NameTypeDefaultDescription
maskMASK
xINT00–16384
yINT00–16384
widthINT5121–16384
heightINT5121–16384

Outputs (1)

NameTypeDescription
MASKMASK