Skip to content
Node packVerifiedExternal
Open source

ComfyUI-Inpaint-CropAndStitch

ComfyUI nodes to crop before sampling and stitch back after sampling that speed up inpainting

Maintainer@lquesadaCgrade

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!

Windlereye on Spotify

Video Tutorial

Video Tutorial

(click to open in YouTube)

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_algorithm and upscale_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
  • InpaintCropImproved
  • InpaintStitchImproved

Related resources

40 connections
Used byFlux Kontext True Inpainting With Krita (Nunchaku compatible) — v2.1Used byFLUX Continuum (Modular Interface for ComfyUI) — v1.7.0Used byUltra photo-realistic workflow | refiner, upscaling, FaceDetailer (+index elements), inpainting, controlnet, Civitai Metadata (NOOBAI-XL/ILLUSTRIOUS/SDXL) ComfyUi — v5.5Used byFisherKing-ZiT-[EyeDetailer]-I2I-ReferenceWorkflow-v1.0 [Low VRAM]Used byFlux.2 Klein Mix Workflow. Consistency, Enhanced, Image Size control, I2I, T2I, In & outpaint, ControlNets. — v1.0Used byFlux Metal Jacket — v3.0Used byZ-image turbo workflow | CivitAI metadata, upscaling, controlnet, FaceDetailer (+indexing elements), inpainting ComfyUI beginner friendly — v1Used byZiT Studio — v1.1Used byWAN 2.1 VACE - Extend, Crop+Stitch, Extra frame workflowUsed byInpaint Anyone or Anything Anywhere Doing Whatever Seamlessly With Krita, Kontext, and Nunchaku — v2.0Used byUltra photo-realistic workflow | refiner, upscaling, FaceDetailer (+index elements), inpainting, controlnet, Civitai Metadata (NOOBAI-XL/ILLUSTRIOUS/SDXL) ComfyUi — v5.25Used byUtopian Inpainting workflow — v2.2Used byUtopian Inpainting workflow — v2.1Used bySimple Kontext Inpaint Cropping workflow — v1.0Used byZ-image turbo workflow | CivitAI metadata, upscaling, controlnet, FaceDetailer (+indexing elements), inpainting ComfyUI beginner friendly — v2Used byKrea2 workflow | ti2i 16GB VRAM CivitAI metadata, upscaling, controlnet, FaceDetailer (+indexing elements), inpainting ComfyUI beginner friendly K2 — v2 — v4Used byZiT Studio — v1.0Used byFlux.2 Klein Mix Workflow. Consistency, Enhanced, Image Size control, I2I, T2I, In & outpaint, ControlNets. — v3.0Used byFLUX.1-DEV & Kontext Workflows Megapack — 🟢F.1 Inpainting 2.2Used byZ-image turbo workflow | CivitAI metadata, upscaling, controlnet, FaceDetailer (+indexing elements), inpainting ComfyUI beginner friendly — v3Used byUltra photo-realistic workflow | refiner, upscaling, FaceDetailer (+index elements), inpainting, controlnet, Civitai Metadata (NOOBAI-XL/ILLUSTRIOUS/SDXL) ComfyUi — v6Used byFast inpaint with cropping (Flux Klein 4b, 9b, etc) — v1.0 — Qwen 2.1 v1.0Used byUtopian Inpainting workflow — v2.0Used byKrea2 workflow | ti2i 16GB VRAM CivitAI metadata, upscaling, controlnet, FaceDetailer (+indexing elements), inpainting ComfyUI beginner friendly K2 — v2 — v8Used byAnima adetailer face workflow — v1.0 — qwenImgv1.0Used by最强换脸换头 — v1.1Used byFLUX.1-DEV & Kontext Workflows Megapack — 🟢 F.1 Kontext 1.4Used byInpaint Anyone or Anything Anywhere Doing Whatever Seamlessly With Krita, Kontext, and Nunchaku — v3.0Used byTrue Inpainting With Kontext (Nunchaku compatible) — v1.0Used byUltra photo-realistic workflow | refiner, upscaling, FaceDetailer (+index elements), inpainting, controlnet, Civitai Metadata (NOOBAI-XL/ILLUSTRIOUS/SDXL) ComfyUi — v4Used byKrea2 workflow | ti2i 16GB VRAM CivitAI metadata, upscaling, controlnet, FaceDetailer (+indexing elements), inpainting ComfyUI beginner friendly K2 — v2 — v7Used byKrea2 workflow | ti2i 16GB VRAM CivitAI metadata, upscaling, controlnet, FaceDetailer (+indexing elements), inpainting ComfyUI beginner friendly K2 — v2Used byUtopian Inpainting workflow — v1.5Used byFast inpaint with cropping (Flux Klein 4b, 9b, etc) — v1.0Used byLustify Workflows [Krea 2, SDXL] — SDXL DMD2Used byFlux.2 Klein Mix Workflow. Consistency, Enhanced, Image Size control, I2I, T2I, In & outpaint, ControlNets. — v2.0Used byUltra photo-realistic workflow | refiner, upscaling, FaceDetailer (+index elements), inpainting, controlnet, Civitai Metadata (NOOBAI-XL/ILLUSTRIOUS/SDXL) ComfyUi — v5.0Used byLooping detailer / inpaint / fixer — v1.0Used bySimple Kontext Inpaint Cropping workflow — v2.0Used bySynariAI / OFMTech / MarlAI - OFM Tech 2.0 — v1.0

Sources

3 sources

Source excerpts

1 excerpt

Source context: Repo lquesada/ComfyUI-Inpaint-CropAndStitch