Skip to main content
Inpainting allows you to selectively edit or regenerate specific regions of an image while preserving the rest. This is essential for fixing details, removing objects, or seamlessly adding new elements.

How Inpainting Works

  1. Define area: Create a mask marking the region to regenerate
  2. Encode: Convert image and mask to latent space
  3. Denoise: Only regenerate the masked area
  4. Decode: Blend seamlessly with unmasked regions
ComfyUI supports two inpainting approaches:
  • Standard models with VAEEncodeForInpaint
  • Dedicated inpaint models with InpaintModelConditioning

Standard Model Inpainting

Works with any Stable Diffusion model.

Workflow JSON: Standard Inpainting

Inpaint Model Workflow

Dedicated inpaint models (like SD 1.5 inpaint) produce better results for complex edits.

Workflow JSON: Inpaint Model

Common Use Cases

Object Removal

Goal: Remove unwanted elements
  1. Mask the object to remove
  2. Prompt what should be there instead
  3. Use high grow_mask_by (8-16) for better blending
Settings:

Adding Elements

Goal: Insert new objects or details
  1. Mask where new element should appear
  2. Detailed prompt describing the addition
  3. Include lighting/style context
Example:

Face/Detail Fixing

Goal: Improve specific details
  1. Mask problem area tightly
  2. Describe desired result
  3. Low grow_mask_by (2-4)
Settings:

Background Extension (Outpainting)

Goal: Expand image borders
  1. Use ImagePadForOutpaint node to extend canvas
  2. Mask the new area
  3. Prompt continuation of the scene
The node outputs both padded image and automatic mask.

Mask Creation Tips

Manual Masking

  1. Use image editor (Photoshop, GIMP, etc.)
  2. White = regenerate, Black = keep
  3. Soft edges with blur for better blending
  4. Save with alpha channel

Mask from Alpha Channel

Use LoadImageMask:
Channels: alpha, red, green, blue

Feathering

grow_mask_by creates smooth transitions:
  • Small objects: 4-8
  • Medium areas: 8-16
  • Large regions: 16-32
  • Full image blend: 40+

Advanced Techniques

Multi-Region Inpainting

  1. Create mask with multiple separate areas
  2. Prompt describes all areas together
  3. Higher steps (40-60) for complexity

Iterative Refinement

  1. First pass: Rough inpaint, denoise 1.0
  2. Save result
  3. Second pass: Load result, smaller mask, denoise 0.6-0.8
  4. Refine specific details

Compositional Inpainting

Use ConditioningSetMask for regional prompts:
This applies prompt only to masked region, giving precise control.

Parameter Guide

grow_mask_by

  • 0: Hard edges, visible seams
  • 2-4: Tight blending, detail work
  • 6-8: Standard blending (default)
  • 12-16: Soft transitions, large areas
  • 32+: Very gradual blend, outpainting

Steps

  • 20-30: Quick edits, simple fills
  • 30-40: Standard quality
  • 40-60: Complex inpainting, multiple objects
  • 60+: Challenging blends, high detail

CFG Scale

  • 6-7: Natural blending, less artifacts
  • 7-8: Balanced (recommended)
  • 8-10: Strong prompt adherence, adding specific objects
  • 10+: Risk of oversaturation at mask edges

Troubleshooting

Visible seams

  • Increase grow_mask_by (try 12-20)
  • Lower CFG scale (try 6-7)
  • Increase steps (35-50)
  • Use softer mask edges

Generated area doesn’t match

  • Describe surrounding context in prompt
  • Include lighting/style references
  • Try dedicated inpaint model
  • Increase CFG for stronger adherence

Blurry results

  • Increase steps (40+)
  • Use better sampler (dpm++ sde karras)
  • Check VAE quality
  • Try dedicated inpaint model

Changes bleed outside mask

  • Reduce grow_mask_by
  • Use hard-edged mask
  • Enable noise_mask (inpaint models)
  • Lower denoise slightly (0.95)

Best Practices

  1. Match the style: Prompt should describe existing image style
  2. Contextual prompts: Reference surrounding elements
  3. Start simple: Test with small masks first
  4. Iterate: Run multiple generations, pick best
  5. Feather appropriately: Match grow_mask_by to edit size
  6. Consider dedicated models: Better for complex edits
  7. Higher steps: Inpainting benefits from extra refinement

Next Steps

  • Combine with ControlNet for precise inpainting
  • Explore regional prompting with ConditioningSetMask
  • Try different inpaint-specific models
  • Experiment with outpainting for image extension