Nodes/ComfyUI-Image-Inpainting/Paste Back Crop Image Inpaint
ComfyUI Node

Paste Back Crop Image Inpaint

The last node in the pipeline — pasting the surgery back together

By SherryXieYuchen·Created 2 years ago·Updated 2 years ago· 4
Paste Back Crop Image Inpaint
  • image
  • crop_image
  • rect
  • IMAGE

"Paste Back Crop Image Inpaint" is where this whole pack's crop-and-stitch pattern lands. You cropped a region, inpainted it, maybe upscaled and composited it - and now you need to put it back into the original image at exactly the right spot. That's this node, and it's as close to a one-click stitch as you get.

Crop-and-stitch is the discipline inpainting has been begging for since the beginning: do the generation work on a tight crop at high resolution, then paste only that region back so the unmasked pixels survive untouched. The KB essay on inpainting makes the case bluntly - the community's oldest rule is "composite after inpainting" because a VAE encode/decode cycle degrades everything it touches. Crop, fix, stitch back: nothing outside the rectangle ever moves. That's the whole point of the pack's INPAINT_CropImage → ... → INPAINT_PasteBackCropImage chain.

How it works

Three inputs, one output. image is the original full frame, crop_image is the finished, fixed region, and rect is the pack's RECT type - the same (x_min, y_min, x_max, y_max) tuple that INPAINT_CropImage produced on its third output. The node resizes nothing and blends nothing; it's a raw slice assignment:

image_numpy[y_min:y_max, x_min:x_max] = crop_image_numpy

The IMAGE that comes out is the original with the crop dropped in. In the bundled workflow this is the very last node before the save/preview - the actual blending happened one step earlier via ImageCompositeMasked with a dilated, blurred mask, and paste-back is the clean final commit.

The two things that bite

Blend before you paste, not after. This node is a hard overwrite with a sharp rectangular boundary. If you paste a rect whose edges weren't feathered, you'll see the seam. The intended order is: composite your inpainted result onto the crop using a soft mask first, then paste the whole composited crop back.

The crop should match the rect. Numpy will happily do the slice assignment regardless, but if crop_image isn't the same size as the rect's region you get a stretched, tiled, or cropped mess. Keep the crop and the rect from the same source - that's what the RECT output of INPAINT_CropImage is for.

It's also a single-image node: everything goes through squeeze(0), so feed it one frame at a time, not a batch.

Install and use

Same pack install as everywhere else in SherryXieYuchen/ComfyUI-Image-Inpainting:

cd ComfyUI/custom_nodes
git clone https://github.com/SherryXieYuchen/ComfyUI-Image-Inpainting
# restart ComfyUI

(Or ComfyUI Manager → search "ComfyUI-Image-Inpainting".) This node has no model requirements of its own - it's pure numpy. If you're only doing lightweight crop-and-stitch with your own inpaint method, you can honestly use this node with none of the pack's models installed. It doesn't know LaMa exists; it just pastes.

Categoryimage

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
crop_imageIMAGE
rectRECT

Outputs (1)

NameTypeDescription
IMAGEIMAGE