Crop Image and Mask
Crop Image and Mask
- image_in
- mask_in
- image_out
- mask_out
This is the "crop to the interesting bit" node. Feed it an image and a mask, and it crops both down to the bounding box of the mask, with padding you control. It's the first half of the crop-refine-paste loop that makes inpainting and detailing actually work - you cut out the region that matters, do expensive work on just that region at full resolution, then paste it back.
Why you'd reach for it
Here's the problem it solves. If a face takes up 80x80 pixels of a 1024x1024 image and you want to fix it, running your whole 1024x1024 frame through another sampling pass wastes almost all the compute on pixels you don't care about - and the face still only gets 80x80 worth of the model's attention. The fix, which Impact Pack's FaceDetailer made standard practice, is to crop to the masked region, upscale that, resample it properly, and composite it back. crop gives you the manual, wire-it-yourself version of that first step, so you can build the loop out of primitives instead of one black-box detailer node.
Because it crops the mask alongside the image with the same box, whatever you do downstream stays aligned - the mask still marks the same pixels relative to the cropped region.
How it works
It scales the mask to match the image, finds the region the mask covers, expands that box by your padding values, and crops both the image and the mask to it. The one behavior worth memorizing: if the mask is empty, it returns the image and mask unchanged. That's a deliberate safety valve - a detection step that found nothing won't crash your graph, it just passes the frame through.
The inputs that matter
- image_in / mask_in - the image and its mask. The mask's bounding box defines the crop.
- vertical_padding / horizontal_padding - extra pixels added top/bottom and left/right around the mask box. You almost always want some padding here so the resampled region has context to blend into; a tight crop right on the mask edge tends to produce hard seams.
- global_padding - pads both width and height at once, a shortcut when you want the same margin all around.
Outputs are image_out and mask_out - the cropped image and the correspondingly cropped mask, which you carry together through the refine step and hand to a paste/composite node to put it back.
Installing it
ComfyUI Manager → search antrobots ComfyUI Nodepack, install, restart. Or clone it:
cd ComfyUI/custom_nodes
git clone https://github.com/antrobot1234/antrobots-comfyUI-nodepack
No models or heavy dependencies - it's a pixel/mask operation.
Common issues
Two things bite people. First, too little padding: crop tight to the mask and the region you paste back has no surrounding context, so the seam shows. Add 32–64px of padding (via the vertical/horizontal or global inputs) and the blend gets much more forgiving.
Second, the empty-mask pass-through can look like a bug when it isn't. If crop seems to be doing nothing, check whether your mask actually has any white pixels - if it's fully black (empty), the node is behaving exactly as designed and handing the full image straight through. That usually means the upstream detector or mask-maker didn't find anything, not that crop failed.
If you plan to paste the result back at its original position, keep the crop box and padding consistent across the crop and paste steps - mismatched padding is the usual cause of a refined region landing slightly offset.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image_in | IMAGE | — | |
| mask_in | MASK | — | |
| vertical_padding | INT | 00–9223372036854776000 | — |
| horizontal_padding | INT | 00–9223372036854776000 | — |
| global_padding | INT | 00–9223372036854776000 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image_out | IMAGE | — |
| mask_out | MASK | — |