Inpainting is the task of filling a masked region of an image with new content that is consistent with the visible surroundings, so that the edited area blends seamlessly into the original. In Generative AI, inpainting is usually performed by a diffusion model or a GAN that receives three inputs: the source image, a binary or soft mask marking the pixels to replace, and often a text prompt describing what should appear there.
The technique serves two related purposes. Restoration inpainting removes scratches, watermarks, unwanted objects or damaged areas and reconstructs a plausible background, while creative inpainting inserts new objects, changes clothing or replaces a sky. Both rely on the same principle: the model must infer missing pixels from global context and local texture at the same time.
How diffusion-based inpainting reconstructs masked pixels
Modern inpainting works by denoising only the masked region while keeping the unmasked region anchored to the source image. In a latent diffusion model, the image is first encoded into latent space by a variational autoencoder, the mask is downsampled to the latent resolution, and the masked latents are replaced with noise before the reverse diffusion process begins.
Two architectural approaches dominate. A dedicated inpainting model extends the denoising network with extra input channels, typically nine channels instead of four in Stable Diffusion inpainting checkpoints: four for the noisy latent, four for the encoded masked image and one for the mask. A standard model with mask blending uses an unmodified network and, at every denoising step, overwrites the unmasked latents with a correctly noised copy of the original, a method often called RePaint-style blending.
The table below summarizes the inputs that a typical diffusion inpainting pipeline consumes and what each one controls.
| Input | Form | What it controls |
|---|---|---|
| Source image | RGB pixels encoded to latents | Context, lighting and perspective |
| Mask | Binary or feathered grayscale map | Which pixels may change |
| Text prompt | Token sequence for the text encoder | Semantic content of the fill |
| Denoising strength | Value from 0.0 to 1.0 | How far the fill departs from the original |
| Guidance scale | Typically 4 to 12 | How strictly the prompt is followed |
After the final step, the decoder converts latents back to pixels. Because the VAE round trip slightly alters even unmasked areas, careful pipelines paste the original pixels back outside the mask and apply a short feathered transition at the boundary.
Classical, GAN and diffusion inpainting methods
Inpainting predates deep learning by decades. Classical methods propagate information from the boundary inward, either by solving partial differential equations that extend edges and gradients or by exemplar-based patch matching that copies similar texture patches from elsewhere in the image. These methods excel at small, repetitive gaps but cannot invent semantically new structure.
GAN-based inpainting introduced learned priors, with networks such as partial-convolution and gated-convolution models trained to fool a discriminator. Large-mask models with Fourier convolutions extended the receptive field so the network could reason about the whole image. Diffusion models then added text conditioning and high diversity, at the cost of slower inference.
The comparison below shows where each family of methods fits best.
| Method family | Strength | Weakness | Typical speed |
|---|---|---|---|
| PDE diffusion | Smooth fills of thin scratches | Blurs large regions | Milliseconds |
| Patch matching | Realistic repeated texture | No new objects | Under a second |
| GAN inpainting | Fast, coherent large masks | Limited diversity, no prompt | Tens of milliseconds |
| Diffusion inpainting | Prompt control, high realism | Slower, may hallucinate detail | Seconds per image |
Inpainting compared with related generative editing tasks
Inpainting is one member of a family of mask- and image-conditioned edits, and the distinctions matter when choosing a workflow. Image-to-image generation modifies the whole frame according to a denoising strength, whereas inpainting confines change to the mask. Outpainting is the mirror case: the mask covers new canvas outside the original borders, so the model extends the scene rather than repairing it.
ControlNet and similar conditioning adapters are often combined with inpainting to constrain pose, edges or depth inside the masked region. Style transfer changes appearance globally and does not reconstruct missing content at all.
| Task | Region that changes | Main use |
|---|---|---|
| Inpainting | Pixels inside the mask | Remove or replace objects |
| Outpainting | New canvas beyond the borders | Extend a scene or change aspect ratio |
| Image-to-image | Entire image, to a set strength | Restyle or vary a composition |
| Style transfer | Entire image appearance | Apply an artistic look |
Configuring masks, strength and context for clean results
Most inpainting quality problems come from mask design and parameter choice rather than from the model itself. A mask drawn tightly around an object leaves its shadow and reflection untouched, so practitioners usually dilate the mask by 8 to 32 pixels and include cast shadows. A feathered edge of a few pixels reduces visible seams.
Resolution also matters. Many tools offer an inpaint-at-full-resolution mode that crops the masked area plus a context margin, upscales it to the native resolution of the model, generates the fill and scales it back. This greatly improves detail on small regions such as faces or hands, but a margin that is too narrow removes the context the model needs to match lighting.
The decision table below lists common situations and recommended settings.
| Goal | Recommended setting | Reason |
|---|---|---|
| Remove a small object | Empty or background prompt, strength 0.8 to 1.0 | Fill should match surroundings |
| Replace clothing | Descriptive prompt, strength 0.6 to 0.9 | Keep body shape and pose |
| Fix a distorted hand | Crop-and-upscale mode, moderate strength | More pixels for fine detail |
| Add a new object | Dedicated inpainting checkpoint, full strength | Needs new structure, not texture |
Limitations, artifacts and responsible use
Inpainting fails in recognizable ways. Seams and color shifts appear when the fill does not match exposure or noise grain, repeated texture betrays patch-based reconstruction, and semantic hallucination occurs when a diffusion model invents plausible but false detail, such as text on a sign that never existed.
- Small masks with low strength often change almost nothing, because the model is anchored too strongly to the original.
- Masks with hard edges produce halos; feathering and post-blending remove them.
- Faces and readable text are the hardest content and usually need several attempts or a specialized model.
- Forensic detectability varies: inpainted regions can leave statistical traces, but detection is not reliable enough to prove authenticity.
Because inpainting can remove people, alter evidence or fabricate events, it raises provenance and disclosure obligations. Content credentials based on the C2PA specification and clear editorial labeling are the established practices for showing that an image was edited, and inpainted images should never be presented as unaltered documentation.
Put simply
Imagine a photograph with a hole cut out of it. Inpainting is a way of asking a computer to paint the missing piece back in so well that nobody notices the hole was ever there. You show it the photo, mark the area you want changed, and optionally describe what should go there.
The computer looks at everything around the hole, such as colors, light and shapes, and invents pixels that fit. The key idea is that only the marked area changes, while the rest of the picture stays exactly as it was. It works like a skilled restorer touching up a damaged painting, except that it can also add something entirely new.
In practice
A real estate photographer delivers 40 interior photos of an apartment, but the client asks for a power cable, a trash bin and a reflection of the photographer in a window to disappear. Instead of reshooting, the retoucher opens each image in an inpainting tool built on a latent diffusion model.
For the cable, the retoucher paints a mask with a 12-pixel dilation, leaves the prompt empty and uses full denoising strength, so the model reconstructs the wooden floor. For the window reflection, a prompt describing “city view through clean glass” guides the fill, with crop-and-upscale mode enabled for detail. Each edit takes under a minute, and the full set is delivered the same day with no visible seams. The listing notes that the photos were digitally retouched, following the agency disclosure policy.