How to Inpaint and Fix Part of an Image in ComfyUI
Use the mask editor and an inpaint workflow to repaint a specific region, like fixing a hand or removing an object, without touching the rest.
Inpainting lets you change only a masked part of an image while keeping everything else. It is how you fix a broken hand, swap a background object, or remove an unwanted element. ComfyUI has a built-in mask editor plus dedicated inpaint nodes that make this reliable.
What you need
- An image to edit (generated or imported)
- A checkpoint; an inpainting-specialized checkpoint works best but a normal one is fine
- A few minutes to paint the mask
Step 1: Load the image
Add a Load Image node and select your file, or drag the image straight onto the node. If you want to edit something you just generated, save it first, then load it back in.
Step 2: Paint the mask
Right-click the Load Image node and choose Open in MaskEditor. Paint over the region you want to change with the brush, adjust the brush size as needed, then click Save to node. The painted area becomes the mask.
Step 3: Encode for inpainting
Add a VAE Encode (for Inpainting) node. Feed it the image, the mask, and your VAE. This produces a latent that tells the sampler which pixels are locked and which are free to change.
Step 4: Prompt for only the masked area
Your positive prompt should describe what you want in the masked region, in the context of the whole scene. To remove an object, describe what should be there instead, for example the wall or sky behind it. Connect the encoded latent into a KSampler.
Step 5: Decode, check, repeat
Run a VAE Decode and Save Image. If the seam shows or the fix is not quite right, change the seed or grow the mask slightly and queue again. Inpainting is iterative, so expect a few attempts.
a clean red brick wall, even lighting, matching the surrounding textureResult: a targeted edit that blends with the original image. The unmasked pixels stay byte-for-byte the same, so only your chosen region changes.
Watch related tutorials
13:20
11:05
19:48
20:00
19:00
32:00