Img2Img, Inpainting & Upscaling
Once you move past text-to-image, ComfyUI lets you restyle existing pictures, make instruction-based edits, repaint masked regions, extend canvases, and upscale cleanly in multiple passes.
#Image-to-Image (Img2Img)
Img2Img replaces Empty Latent Image with Load Image -> VAE Encode so the KSampler starts from encoded pixels instead of pure noise.
- Add
Load Imageand upload or drop your source picture. - Connect
Load ImageIMAGE ->VAE Encodepixels (plus your VAE input). - Connect
VAE EncodeLATENT ->KSamplerlatent_image. - Lower
denoisebelow1.00to keep parts of the original structure:
denoise range |
Effect on the input image | Best use case |
|---|---|---|
0.15 - 0.30 |
Crisp texture/lighting polish while preserving layout | Second-pass refinement and subtle cleanup |
0.35 - 0.55 |
Restyles brushwork, lighting, or details while holding pose | Style shifts and Hi-Res Fix passes |
0.60 - 0.80 |
Heavy reimagining while roughly honoring color/composition | Turning rough sketches into finished renders |
0.85 - 1.00 |
Replaces almost everything | Effectively a fresh generation |
#Instruction-based editing (native edit models)
Modern unified and edit-trained models let you describe edits in plain language ("replace the red jacket with a weathered leather coat", "shift lighting to sunset") without manually painting masks:
- Reference-latent edit models (
Flux.2 Klein,Flux.1 Kontext,Krea 2): encode one or more input images withVAE Encodeand inject them into conditioning viaSet Reference Latent(ReferenceLatent) orSet Reference Multi Latent(ReferenceMultiLatent). UseFluxKontextImageScalewhen preparing Flux.1 Kontext inputs. - Qwen-Image 2.1 (
Text Encode Qwen Image 2.1): handles both text-to-image and multi-reference image editing inside one model, accepting up to 16 reference images directly in its conditioning node while outputting a matched 64-channellatent.
Check Workflow > Browse Templates inside ComfyUI for each model family's exact reference-conditioning graph.
#Inpainting (selective masked edits)
When you want surgical control over exactly which pixels change, use ComfyUI's built-in MaskEditor on Load Image:
- Right-click a
Load Imagenode and click Open in MaskEditor. - Paint over the exact region you want to change (clothing, hand, background object), adjust brush hardness/opacity, and click Save.
- Wire your mask using one of three built-in paths:
- General models: connect
VAE EncodeandLoad ImageMASK intoSet Latent Noise Mask->KSampler. AddDifferential DiffusiononMODELfor smooth feathered blending at moderate denoise values. - Conditioning-masked / Flux-style inpaint: use
InpaintModelConditioningso masked latents and unmasked pixels stay locked together cleanly. - Dedicated inpaint checkpoints: use
VAE Encode (for Inpainting)withgrow_mask_byset to6 - 12pixels so borders blend smoothly.
- General models: connect
- For tiny faces or hands on large canvases, crop around the subject before sampling (for example with
Crop Image/Maskhelpers or community crop-and-stitch nodes) and paste back so small details receive full native resolution.
#Outpainting (extending borders)
To reveal more scenery around an existing crop:
- Insert
Pad Image for OutpaintingafterLoad Image. - Enter pixel padding on
left,top,right, orbottom, plusfeathering(32 - 64px) to blend the seam. - Connect its
IMAGEandMASKoutputs intoVAE Encode (for Inpainting)(orSet Latent Noise Mask) and describe the wider scene in your prompt. - Keep
denoiseat1.0so newly padded gray regions synthesize fresh detail cleanly while masked border feathering smooths the transition.
#Hi-Res Fix (two-pass upscale)
Generating directly at 2048x2048 causes repeated faces and distorted anatomy because base models are trained near 1 MP (1024x1024). Instead, generate at native size first, then upscale and refine.
- Run Pass 1 at native resolution (
1024x1024for SDXL/Flux/Anima) and decode withVAE Decode. - Upscale the decoded RGB image with
Load Upscale Model(for example4x-UltraSharpor4x_NMKD-Siax_200k) ->Upscale Image (using Model). - Optionally downscale slightly with
Upscale Image By(0.5after a4xupscaler gives a crisp2xoutput at2048x2048). - Encode back to latent with
VAE Encode(orVAE Encode (Tiled)on 8-12 GB GPUs). - Run Pass 2 through a second
KSamplerwithdenoisebetween0.25and0.45and12 - 20steps, thenVAE DecodetoSave Image.
#Upscaling methods compared
| Method | Pros | Cons |
|---|---|---|
Pixel model upscale + Pass 2 (4x-UltraSharp) |
Preserves sharp edges, eyes, and fabric before re-denoising; lets Pass 2 use lower denoise (0.25 - 0.40) |
Extra VRAM/compute for the ESRGAN model |
Latent upscale (Upscale Latent / models/latent_upscale_models/) |
Fast with low memory overhead; learned latent upscalers avoid simple interpolation blur | Simple interpolation upscalers need higher denoise (0.50+) to sharpen textures |
Diffusion restoration (SeedVR2, built-in) |
Strong generative texture recovery for degraded photos and video; includes Split SeedVR2 Latent and Merge SeedVR2 Latents for chunked video upscaling |
Heavier compute than single-pass ESRGAN models |
#Tiled passes for 4K+ and low VRAM
When decoding or refining images above 2048 x 2048:
- Replace
VAE DecodewithVAE Decode (Tiled)(built into ComfyUI) to avoid sudden out-of-memory crashes right at the finish line. - For ultra-high resolutions or seamless multi-tile refinement, use tiled diffusion or
Ultimate SD Upscale(keeping tile overlap at64 - 128px and moderate denoise0.20 - 0.35).
Next: lock pose, depth, edges, and style references in ControlNet & Style References.