Learn ComfyUI Image Generation: FLUX, ControlNet, and LoRA Inpainting and Outpainting

Inpainting and Outpainting

Intermediate 🕐 20 min Lesson 6 of 11
What you'll learn
  • Create a mask using ComfyUI's built-in mask editor and load it into an inpainting workflow.
  • Build a working inpainting workflow using VAE Encode (for inpainting) or InpaintModelConditioning.
  • Extend an image canvas using the Pad Image for Outpainting node and an inpainting model.

Targeting Specific Areas of an Image

Inpainting lets you regenerate selected regions of an existing image while leaving everything else unchanged. The process uses a mask — a black-and-white image where white areas are regenerated and black areas are preserved. This is how you fix a bad face, replace an unwanted object, add elements to an otherwise-good image, or correct hands that came out distorted.

Outpainting is the reverse concept: instead of regenerating inside the existing canvas, you extend the canvas beyond its original boundaries and generate new content that blends seamlessly with what's already there. A portrait can become a full-body shot. A landscape can gain additional sky or foreground.

Creating a Mask in ComfyUI

There are two main ways to create a mask in ComfyUI:

  • Built-in mask editor: Add a Load Image node. Right-click on it after loading your image and select "Open in MaskEditor." Paint white over the area you want to regenerate (scroll to zoom, use the brush size slider). Black stays, white gets replaced. Click "Save" to use the mask in your workflow. The mask output port appears on the Load Image node after saving.
  • Separate Load Image for mask: If you already have a prepared black-and-white mask image file, use a second Load Image node for the mask and use its IMAGE output as a mask input to other nodes. You may need a Convert Image to Mask node to convert the image to the MASK data type.

For clean inpainting results, paint your mask slightly larger than the actual problem area. A mask that is too small leaves a hard edge where the inpainted area meets the original content. Feathering the mask edges (using a Blur Mask node) creates a smoother blend.

The Inpainting Workflow

ComfyUI offers two approaches to inpainting depending on whether you're using a standard checkpoint or an inpainting-specific checkpoint:

Standard checkpoint with VAE Encode (for inpainting):

  1. Load Image → image
  2. Load Image (mask) → MASK (from mask editor or separate file)
  3. VAE Encode (for inpainting) node: takes image, vae, mask as inputs; outputs latent with the masked area set to noise
  4. KSampler: denoise set to 0.9–1.0 for the masked area
  5. VAE Decode → Save Image

Inpainting-specific checkpoint: Some checkpoints have "inpaint" in the name (e.g., sd_xl_inpaint-0.1.safetensors). These use the InpaintModelConditioning node instead of VAE Encode for inpainting. The node takes positive conditioning, negative conditioning, vae, pixels (image), and mask as inputs, outputting conditioning and latent. These checkpoints generally produce better edge blending.

For the denoise setting when inpainting: use 0.9–1.0 if the area needs to be completely different, 0.6–0.8 if you want the replacement to stay consistent with the surrounding content.

Softening Edges with Blur Mask

Hard mask edges often produce visible seams where the inpainted area meets the original. Add a Blur Mask node between your mask output and the VAE Encode (for inpainting) input. Set the blur amount to 5–20 pixels depending on how large the inpainted area is. Larger areas need more blur for a natural blend; smaller areas need less to avoid spilling into surrounding content.

Outpainting with the Pad Image for Outpainting Node

Outpainting extends your canvas. The workflow:

  1. Load your base image
  2. Add a Pad Image for Outpainting node: set how many pixels to add on each side (left, right, top, bottom). The node outputs a padded image and a mask that marks the new empty area.
  3. Connect the padded image and mask into an inpainting workflow (VAE Encode for inpainting or InpaintModelConditioning)
  4. Write a prompt that describes what should appear in the extended area — be specific about what the expanded region should contain
  5. Set denoise to 1.0 for the new area (it starts as blank canvas)

For best results, outpaint in increments rather than all at once. Adding 30% of extra canvas per pass gives the model enough context from the existing image to generate coherent extensions. Multiple outpainting passes in different directions can dramatically expand the original composition.

Key takeaways
  • The mask editor is built into the Load Image node — right-click after loading and select Open in MaskEditor; paint white on the area to regenerate and black on the area to preserve.
  • Two inpainting workflows exist: standard checkpoints use VAE Encode (for inpainting) with the mask, while dedicated inpainting checkpoints use InpaintModelConditioning — the dedicated approach generally blends edges better.
  • Adding a Blur Mask node before the VAE Encode step softens mask edges to prevent visible seams between inpainted and original content — 5–20 pixels of blur depending on the mask size.
  • Outpainting uses the Pad Image for Outpainting node to extend the canvas with a matching mask — write a specific prompt about the new area and set denoise to 1.0 since the extension is blank.
  • Outpainting in small increments (30% canvas expansion per pass) produces more coherent results than trying to extend the image a large amount in one step.