# 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. 1. Add `Load Image` and upload or drop your source picture. 2. Connect `Load Image` **IMAGE** -> `VAE Encode` **pixels** (plus your **VAE** input). 3. Connect `VAE Encode` **LATENT** -> `KSampler` **latent_image**. 4. Lower `denoise` below `1.00` to 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 with `VAE Encode` and inject them into conditioning via **`Set Reference Latent`** (`ReferenceLatent`) or **`Set Reference Multi Latent`** (`ReferenceMultiLatent`). Use `FluxKontextImageScale` when 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-channel `latent`. 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`: 1. Right-click a `Load Image` node and click **Open in MaskEditor**. 2. Paint over the exact region you want to change (clothing, hand, background object), adjust brush hardness/opacity, and click **Save**. 3. Wire your mask using one of three built-in paths: * **General models:** connect `VAE Encode` and `Load Image` **MASK** into **`Set Latent Noise Mask`** -> `KSampler`. Add **`Differential Diffusion`** on `MODEL` for smooth feathered blending at moderate denoise values. * **Conditioning-masked / Flux-style inpaint:** use **`InpaintModelConditioning`** so masked latents and unmasked pixels stay locked together cleanly. * **Dedicated inpaint checkpoints:** use **`VAE Encode (for Inpainting)`** with `grow_mask_by` set to `6 - 12` pixels so borders blend smoothly. 4. For tiny faces or hands on large canvases, crop around the subject before sampling (for example with `Crop Image` / `Mask` helpers or community crop-and-stitch nodes) and paste back so small details receive full native resolution. > [!TIP] > If inpainting produces visible square seams, use `InpaintModelConditioning` or `Differential Diffusion` with soft brush edges and `grow_mask_by` around `8`. ## Outpainting (extending borders) To reveal more scenery around an existing crop: 1. Insert **`Pad Image for Outpainting`** after `Load Image`. 2. Enter pixel padding on `left`, `top`, `right`, or `bottom`, plus `feathering` (`32 - 64` px) to blend the seam. 3. Connect its `IMAGE` and `MASK` outputs into `VAE Encode (for Inpainting)` (or `Set Latent Noise Mask`) and describe the wider scene in your prompt. 4. Keep `denoise` at `1.0` so 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. 1. Run Pass 1 at native resolution (`1024x1024` for SDXL/Flux/Anima) and decode with `VAE Decode`. 2. Upscale the decoded RGB image with `Load Upscale Model` (for example `4x-UltraSharp` or `4x_NMKD-Siax_200k`) -> `Upscale Image (using Model)`. 3. Optionally downscale slightly with **`Upscale Image By`** (`0.5` after a `4x` upscaler gives a crisp `2x` output at `2048x2048`). 4. Encode back to latent with `VAE Encode` (or `VAE Encode (Tiled)` on 8-12 GB GPUs). 5. Run Pass 2 through a second `KSampler` with `denoise` between `0.25` and `0.45` and `12 - 20` steps, then `VAE Decode` to `Save 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 Decode` with `VAE 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 at `64 - 128` px and moderate denoise `0.20 - 0.35`). Next: lock pose, depth, edges, and style references in [ControlNet & Style References](./controlnet-and-references.md).