ComfyUI Node

✂️ Inpaint Crop

The node that made masked inpainting sane in ComfyUI

By lquesada·Created 2 years ago·Updated 2 months ago· 1,136
✂️ Inpaint Crop
  • image
  • mask
  • optional_context_mask
  • stitcher
  • cropped_image
  • cropped_mask
downscale_algorithmbilinear
upscale_algorithmbicubic
preresizefalse
preresize_modeensure minimum resolution
preresize_min_width1024
preresize_min_height1024
preresize_max_width16384
preresize_max_height16384
mask_fill_holestrue
mask_expand_pixels0
mask_invertfalse
mask_blend_pixels32
mask_hipass_filter0.10
extend_for_outpaintingfalse
extend_up_factor1.00
extend_down_factor1.00
extend_left_factor1.00
extend_right_factor1.00
context_from_mask_extend_factor1.20
output_resize_to_target_sizetrue
output_target_width512
output_target_height512
output_padding32
device_modecpu (compatible)

If you've ever inpainted a small face in a big image and watched ComfyUI grind through the whole 4K frame just to fix a 64px eye, this is the node that fixes that. Inpaint Crop (the shiny new one, class InpaintCropImproved, shown as "✂️ Inpaint Crop") cuts out just the region around your mask, hands you a clean cropped image and mask to sample on, and - crucially - remembers exactly where it came from so its partner node can paste the result back untouched. It's half of a pair: Crop up front, Inpaint Stitch at the end. You basically never use one without the other.

Why bother instead of masking and sampling the whole picture? It's much faster, because you only denoise a crop. It renders that little region at your model's native resolution - crop a 64px area, blow it up to 512 or 1024, generate real detail, shrink it back. And it never passes the unmasked part of your image through VAE encode/decode, the single biggest cause of the whole picture subtly shifting color every pass. That last property is why this pack became the community default in 2025-26: the old "please composite your image after inpainting" discipline stops being something you remember and becomes a property of the graph.

How it works

Give it an image and a mask. It fills holes in the mask, optionally grows or blurs it, figures out a bounding box that includes some context around the masked area, crops to that box, and resizes the crop to a target resolution you pick. Out come three things. You sample on the crop like any normal img2img/inpaint workflow, then feed the result back to Stitch.

The one non-obvious output is stitcher - not an image, but a bundle of "here's where this crop lives and how it was transformed." Don't wire it anywhere except Stitch. It's the receipt that makes the paste-back pixel-perfect.

The inputs and outputs that matter

Most of the two dozen knobs have sane defaults. The handful a beginner actually touches:

  • mask (optional MASK) - the region you're regenerating. This is the whole point; wire your mask here.
  • output_target_width / output_target_height (default 512×512) - the resolution the crop gets resized to. Set this to your model's native res: 512 for SD 1.5, 1024 for SDXL or Flux. Leave output_resize_to_target_size on.
  • context_from_mask_extend_factor (default 1.2) - how much surrounding image to include for context. 1 = just the mask, 2 = grow it by the mask's size in every direction. More context means the model understands the scene better; too much and you waste resolution on stuff you don't care about.
  • mask_blend_pixels (default 32) - grows and blurs the stitch mask so the paste blends with no visible seam. The default is usually fine.
  • device_mode (default cpu (compatible)) - CPU always works but is slow; gpu (much faster) is 30-100x faster (inputs must fit in VRAM). The default was flipped back to CPU in mid-2026 for compatibility, so switch to GPU yourself if the node is a bottleneck.

There's also extend_for_outpainting (with per-direction factors) to grow the canvas, preresize to force a min/max resolution first, plus mask_fill_holes, mask_expand_pixels, and mask_hipass_filter (ignores near-black mask values below 0.1). Ignore most of those until you need them.

Outputs: cropped_image and cropped_mask go into your sampling chain, and stitcher goes straight to Inpaint Stitch.

How to install it

Search ComfyUI-Inpaint-CropAndStitch in ComfyUI Manager and install, or drop to a terminal:

cd ComfyUI/custom_nodes
git clone https://github.com/lquesada/ComfyUI-Inpaint-CropAndStitch.git

then restart ComfyUI. There are no model downloads and no heavy dependencies for the nodes themselves - it's pure image and mask math (GPL-3.0, by Luis Quesada Torres). The example workflows in the repo pull real models (a Flux GGUF, an inpainting ControlNet, 4x-UltraSharp), but that's the workflow's requirement, not the node's.

Common issues & troubleshooting

"I can still see the original image through my inpaint." This is the number-one report and it's almost always the mask, not the node. Your mask isn't 100% opaque - even shades of grey your eye reads as white count as partial mask. The author's own advice: screenshot it and check the pixels are actually 255,255,255 / #FFFFFF. If you use fill-holes, make sure the whole boundary is pure white too.

Denoise is stuck at 1 / the fix ignores the original. Use InpaintModelConditioning in your sampling chain instead of "VAE Encode (for Inpainting)" - that's what lets you run denoise below 1 for subtle changes. And use an actual inpainting checkpoint (e.g. a ...Inpainting variant) for clean edges.

Double heads or doubled bodies in the crop mean you upscaled a region larger than the model wants to draw one subject in. Downscale instead, or lower the target resolution.

It's slow on video. Switch device_mode to gpu (much faster) - both crop and stitch move to VRAM and get dramatically faster, as long as the inputs fit.

Categoryinpaint

Inputs (27)

NameTypeDefaultDescription
imageIMAGE
downscale_algorithmCOMBObilinear6 options: nearest, bilinear, bicubic, lanczos, box, hamming
upscale_algorithmCOMBObicubic6 options: nearest, bilinear, bicubic, lanczos, box, hamming
preresizeBOOLEANfalseResize the original image before processing.
preresize_modeCOMBOensure minimum resolution3 options: ensure minimum resolution, ensure maximum resolution, ensure minimum and maximum resolution
preresize_min_widthINT10240–16384
preresize_min_heightINT10240–16384
preresize_max_widthINT163840–16384
preresize_max_heightINT163840–16384
mask_fill_holesBOOLEANtrueMark as masked any areas fully enclosed by mask.
mask_expand_pixelsINT00–16384Expand the mask by a certain amount of pixels before processing.
mask_invertBOOLEANfalseInvert mask so that anything masked will be kept.
mask_blend_pixelsINT320–64How many pixels to blend into the original image.
mask_hipass_filterFLOAT0.100–1Ignore mask values lower than this value.
extend_for_outpaintingBOOLEANfalseExtend the image for outpainting.
extend_up_factorFLOAT1.000.01–100
extend_down_factorFLOAT1.000.01–100
extend_left_factorFLOAT1.000.01–100
extend_right_factorFLOAT1.000.01–100
context_from_mask_extend_factorFLOAT1.201–100Grow the context area from the mask by a certain factor in every direction. For example, 1.5 grabs extra 50% up, down, left, and right as context.
output_resize_to_target_sizeBOOLEANtrueForce a specific resolution for sampling.
output_target_widthINT51264–16384
output_target_heightINT51264–16384
output_paddingCOMBO328 options: 0, 8, 16, 32, 64, 128, +2
device_modeCOMBOcpu (compatible)2 options: cpu (compatible), gpu (much faster)
maskoptMASK
optional_context_maskoptMASK

Outputs (3)

NameTypeDescription
stitcherSTITCHER
cropped_imageIMAGE
cropped_maskMASK