Nodes/Comfyui-ergouzi-Nodes/2🐕Cropping image mask areas
ComfyUI Node

2🐕Cropping image mask areas

Auto-crop around a mask and remember how to put it back

By 11dogzi·Created 2 years ago·Updated 2 years ago· 102
2🐕Cropping image mask areas
  • original_image
  • original_mask
  • cropped_image
  • cropped_mask
  • Crop_data
Up0
Down0
Left0
Right0

The README describes this pack's refinement nodes as a "more flexible local processing method" - crop the masked region out, run it through some other node or pipeline entirely, then stitch the result back into the original. This node is the crop half of that loop, and the important part isn't the cropping itself, it's that it hands you back the exact coordinates you'll need to put the processed piece back where it came from. It's the same idea the wider ComfyUI ecosystem eventually converged on with dedicated crop-and-stitch node pairs - ergouzi built its own version of that pattern for this pack. (Worth knowing: 11dogzi isn't a one-node hobbyist here - the same author also maintains a standalone ComfyUI upscaler wrapper that shows up unprompted in r/comfyui upscaler recommendations, which is a decent signal this pack's local-editing tooling wasn't thrown together carelessly either.)

How it works

Give it your full image and its mask. The node finds the bounding box of whatever's masked, optionally pads that box out on each side, and crops both the image and the mask down to that region. The point of cropping instead of processing the whole frame is the same reason "only masked" inpainting exists at all: a small region gets far more effective resolution and model attention cropped-and-upscaled than it ever would sitting inside a full-frame pass. Crop_data is what makes the round trip possible - it carries the box's position so a matching paste-back node elsewhere in the pack can composite your processed crop into exactly the spot it was cut from, instead of you eyeballing an offset by hand.

The inputs and outputs that matter

  • original_image (IMAGE, required) and original_mask (MASK, required) - what you're cropping.
  • Up, Down, Left, Right (INT, min 0, default 0, optional) - extra padding in pixels on each edge of the crop, beyond the mask's own bounding box.

Three outputs: cropped_image and cropped_mask (the pieces you'll actually process), and Crop_data (a COORDS value - not an image, not a latent - that only matters to the node that stitches the result back in).

How to install it

Search Comfyui-ergouzi-Nodes in ComfyUI Manager, or clone it manually:

cd ComfyUI/custom_nodes
git clone https://github.com/11dogzi/Comfyui-ergouzi-Nodes.git

Restart ComfyUI. Standard caveat for this pack: the README marks the English repo as no longer updated, with further development on a Chinese-named sibling repo instead.

Common issues & troubleshooting

Crop is too tight and the reprocessed region doesn't blend. All four padding values default to 0, so an unpadded call crops exactly to the mask's bounding box with zero surrounding context. Whatever you run on that crop - a sampler, an upscaler, another model entirely - has nothing to blend against at the edges. Bump Up/Down/Left/Right before feeding the crop onward; the same 32-64px-of-context guidance that applies to only-masked inpainting elsewhere applies here too.

Pasted the result back and it landed in the wrong place, or didn't paste at all. Crop_data is the whole point of using this node instead of cropping by hand - it only does anything when it's wired into the matching stitch-back node in this pack. If you cropped, processed, and then tried to composite the result back with a generic image-composite node while ignoring Crop_data, you've thrown away the one thing that made this worth using over a manual crop, and you'll need to re-derive the offset yourself.

Crop comes back empty or throws. This node assumes original_mask actually marks something. If your upstream mask generation failed silently - an empty mask from a detector that found nothing, say - this is usually where you'll notice, since there's no region for the bounding box to find.

Category2🐕/🔍Refinement processing

Inputs (6)

NameTypeDefaultDescription
original_imageIMAGE
original_maskMASK
UpoptINT0
DownoptINT0
LeftoptINT0
RightoptINT0

Outputs (3)

NameTypeDescription
cropped_imageIMAGE
cropped_maskMASK
Crop_dataCOORDS