MaskCropRestore_YC
Stitch a cropped, edited image back onto its background — the 'restore' half of crop-edit-stitch
- background_image
- cropped_image
- crop_coords
- cropped_mask
- crop_frame
- image
- inpaint_mask
This is the second half of the most important inpainting pattern of the last couple of years: crop a region, edit it in isolation, then put it back so the rest of the frame never goes through a VAE. MaskCropRestore_YC is the "put it back" part. You feed it the original background, the cropped-and-edited image, and the crop coordinates from the crop step - and it pastes the edit back in place, optionally masked, and also hands you the exact inpaint mask it used.
The community rule here is blunt: composite after inpainting, or your image degrades with every pass. The 2026 version of that rule is structural - the crop-edit-stitch pair makes it impossible to touch pixels outside the region. This node is the stitch. It pairs with MaskCrop_YC from the same pack (which does the crop and produces the COORDS), and it'll happily consume output from any crop node that gives you (x_min, y_min, x_max, y_max).
How it works
You give it background_image and cropped_image, plus crop_coords (a COORDS tuple). It pastes the cropped image into the background at those coordinates. Then the mask logic kicks in:
cropped_mask(optional) - the region mask from the crop step; the edit only replaces pixels where this is 1.crop_frame(optional) - same idea, slightly different provenance; used ifcropped_maskisn't provided.- Neither provided? It falls back to a full-white mask, i.e. replace the entire crop box.
invert_maskflips whatever mask was used, so you can keep the background and replace only the surround - a quick outpainting-style move.
The output is two things: image (the composited background) and inpaint_mask (the full-canvas mask of exactly what got replaced). That inpaint_mask is the quiet star here - you can feed it to an InpaintModelConditioning or a second pass, or just keep it as documentation of what the node touched.
The code defends against a lot of sloppy inputs (coordinates that clip the canvas, tiny regions, mismatched crop sizes), which is good, but the takeaway is: give it clean coordinates and matching sizes and you get a clean stitch.
Install
Part of ComfyUI-YCNodes. ComfyUI Manager → search "ComfyUI-YCNodes", or:
cd ComfyUI/custom_nodes
git clone https://github.com/yichengup/ComfyUI-YCNodes
Restart ComfyUI. Standard deps, no model downloads. Found under "YCNode/Mask".
Gotchas
The obvious pairing - MaskCrop_YC → edit → MaskCropRestore_YC - works because the crop node's crop_coords output plugs straight into this node's crop_coords input. If you're mixing with a crop node from another pack, make sure the coords are (x_min, y_min, x_max, y_max) in that order; this node unpacks them positionally. And if your crop was scaled up before editing (the whole point of scaling a region before edit), restore the edited crop to the original dimensions first - e.g. with the pack's own ImageScaleRestoreV2_YC - before stitching, or the paste will be misaligned.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| background_image | IMAGE | — | |
| cropped_image | IMAGE | — | |
| crop_coords | COORDS | — | |
| invert_mask | BOOLEAN | false | — |
| cropped_maskopt | MASK | — | |
| crop_frameopt | MASK | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| inpaint_mask | MASK | — |