Nodes/ComfyUI Easy Use/imageCropFromMask
ComfyUI Node Runs on cloud

imageCropFromMask

Crop an image to whatever the mask covers

By yolain·Created 3 years ago·Updated 8 days ago· 2,633
imageCropFromMask
  • image
  • mask
  • crop_image
  • crop_mask
  • bbox
image_crop_multi1.000
mask_crop_multi1.000
bbox_smooth_alpha1.00

easy imageCropFromMask takes an image and a mask, finds the region the mask covers, and crops the image down to that bounding box - handing you back the cropped image, the cropped mask, and the box coordinates. It's the setup step for any "work on just this part" workflow: detail a face, inpaint an object, upscale a region. Instead of resampling the whole frame, you crop to the area that matters, process it at full resolution, and composite it back - the same detect-crop-refine logic that makes detailers work, exposed as a standalone crop.

The reason you crop before processing is resolution economy. A small region inside a big frame gets very little of the model's attention if you resample the whole image; crop it out first and that region fills the canvas, so the model actually has pixels to work with.

How it works

The node reads the mask, computes the tightest bounding box around the masked area, and cuts both the image and the mask to that box. Two multiplier controls let you pad the crop outward - useful because a box that hugs the mask exactly often clips context the model needs to blend cleanly. It also outputs the raw bounding box, so a later node can paste your processed crop back into the exact same spot.

The inputs that matter

  • image and mask - the image to crop and the mask that defines where. The mask is usually coming from a detector, a segmentation node, or a hand-drawn mask.
  • image_crop_multi - how much padding to add around the crop, as a multiplier. Above 1 grows the crop beyond the mask's box, giving the downstream process some surrounding context. A little padding usually blends back better than a tight cut.
  • mask_crop_multi - the same idea for the mask crop.
  • bbox_smooth_alpha - smooths the bounding box over time. This is the one that matters for video: on a per-frame mask, the raw box jitters frame to frame, and smoothing it stops the crop from jumping around. On a single still it does little.

Outputs:

  • crop_image - the cropped image, ready to detail/inpaint/upscale.
  • crop_mask - the mask cropped to match.
  • bbox - the bounding box coordinates, so you can paste the result back accurately.

How to install it

Via ComfyUI Manager: search "ComfyUI Easy Use", install, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/yolain/ComfyUI-Easy-Use

Then install.bat / pip install -r requirements.txt, restart. Preinstalled on comfy.icu.

Common issues

The most common disappointment is a crop that blends back with a visible seam, and the usual cause is cropping too tight - bump image_crop_multi above 1 so there's a margin of real context around the masked region for the downstream pass to feather into.

Second, hold onto that bbox output. The crop is only half the job; the other half is putting the processed region back where it came from, and that needs the bounding box. If you crop, detail, and then can't line the result back up with the original, it's because the paste-back step never got the bbox. And for video, bbox_smooth_alpha is the difference between a stable crop and one that twitches every frame - set it before you render a sequence, not after you notice the jitter.

CategoryEasyUse/Image

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
maskMASK
image_crop_multiFLOAT1.0000–10
mask_crop_multiFLOAT1.0000–10
bbox_smooth_alphaFLOAT1.000–1

Outputs (3)

NameTypeDescription
crop_imageIMAGE
crop_maskMASK
bboxBBOX