ComfyUI-Inpaint-CropAndStitch
ComfyUI nodes to crop before sampling and stitch back after sampling that speed up inpainting
Package profile
- Status
- Verified
- Publisher
- @lquesada
- Source
- GitHub
- Stars
- 1.2K
- Linked pipes
- 1
README
ComfyUI-Inpaint-CropAndStitch
Copyright (c) 2024-2026, Luis Quesada Torres - https://github.com/lquesada | www.luisquesada.com
Check ComfyUI here: https://github.com/comfyanonymous/ComfyUI
Overview
The '✂️ Inpaint Crop' and '✂️ Inpaint Stitch' nodes enable inpainting only on masked area very easily
"✂️ Inpaint Crop" crops the image around the masked area (optionally with a context area that marks all parts relevant to the context), taking care of pre-resizing the image if desired, extending it for outpainting, filling mask holes, growing or blurring the mask, cutting around a larger context area, and resizing the cropped area to a target resolution.
The cropped image can be used in any standard workflow for sampling. It can even be rescaled up with any model (please keep the aspect ratio) and hiRes-fixed and it will be retrofit in the original image.
Then, the "✂️ Inpaint Stitch" node stitches the inpainted image back into the original image without altering unmasked areas.
The main advantages of inpainting only in a masked area with these nodes are:
- It is much faster than sampling the whole image.
- It enables setting the right amount of context from the image for the prompt to be more accurately represented in the generated picture.
- It enables upscaling before sampling in order to generate more detail, then stitching back in the original picture.
- It enables downscaling before sampling if the area is too large, in order to avoid artifacts such as double heads or double bodies.
- It enables forcing a specific resolution (e.g. 1024x1024 for SDXL models).
- It does not modify the unmasked part of the image, not even passing it through VAE encode and decode.
- It takes care of blending automatically.
Support me!
GenAI is not just for the sake of GenAI, but to unblock creativity and empower humans. I am not only a developer; I use GenAI myself to do more things better than I could otherwise do.
Do you like this node? Check, listen to, or follow my GenAI music project Windlereye on Spotify to support me!
Video Tutorial
Note: this video tutorial is for the previous version of the nodes, but still it shows how to use them. The parameters are mostly the same.
Parameters
downscale_algorithmandupscale_algorithm: Which algorithms to use when resizing an image up or down.preresize: Shows options to resize the input image before any cropping: to ensure minimum resolution, to ensure maximum resolution, to ensure both minimum and maximum resolution. This makes it very convenient to ensure that any input images have a certain resolution.mask_fill_holes: Whether to fully fill any holes (small or large) in the mask, that is, mark fully enclosed areas as part of the mask.mask_expand_pixels: Grows the mask by the specified amount of pixels.mask_invert: Whether to fully invert the mask, that is, only keep what was masked, instead of removing what was marked.mask_blend_pixels: Grows the stitch mask and blurs it by the specified amount of pixels, so that the stitch is slowly blended and there are no seams.mask_hipass_filter: Ignores mask values lower than the one specified here. This is to avoid sections in the mask that are almost 0 (black) to count as masked area. Sometimes that leads to confusion, as the user believes the area is not really masked and the node is considering it as masked.extend_for_outpainting: Shows options to extend the mask in any/all directions (up/down/left/right) by a certain factor. >1 extends the image, e.g. 2 extends the image in a direction by the same amount of space the image takes
Nodes in this pack
2 nodes
Nodes in this pack
2 nodes- InpaintCropImproved
- InpaintStitchImproved
Related resources
40 connections
Related resources
40 connectionsSources
3 sources
Sources
3 sourcesVerified Jul 15
Source excerpts
1 excerpt
Source excerpts
1 excerptSource context: Repo lquesada/ComfyUI-Inpaint-CropAndStitch
