Inpainting

On this page 7

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.

InputFormWhat it controls
Source imageRGB pixels encoded to latentsContext, lighting and perspective
MaskBinary or feathered grayscale mapWhich pixels may change
Text promptToken sequence for the text encoderSemantic content of the fill
Denoising strengthValue from 0.0 to 1.0How far the fill departs from the original
Guidance scaleTypically 4 to 12How strictly the prompt is followed
Inputs to a diffusion inpainting pipeline

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 familyStrengthWeaknessTypical speed
PDE diffusionSmooth fills of thin scratchesBlurs large regionsMilliseconds
Patch matchingRealistic repeated textureNo new objectsUnder a second
GAN inpaintingFast, coherent large masksLimited diversity, no promptTens of milliseconds
Diffusion inpaintingPrompt control, high realismSlower, may hallucinate detailSeconds per image
Comparison of inpainting method families

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.

TaskRegion that changesMain use
InpaintingPixels inside the maskRemove or replace objects
OutpaintingNew canvas beyond the bordersExtend a scene or change aspect ratio
Image-to-imageEntire image, to a set strengthRestyle or vary a composition
Style transferEntire image appearanceApply an artistic look
How inpainting differs from neighboring tasks

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.

GoalRecommended settingReason
Remove a small objectEmpty or background prompt, strength 0.8 to 1.0Fill should match surroundings
Replace clothingDescriptive prompt, strength 0.6 to 0.9Keep body shape and pose
Fix a distorted handCrop-and-upscale mode, moderate strengthMore pixels for fine detail
Add a new objectDedicated inpainting checkpoint, full strengthNeeds new structure, not texture
Recommended settings by editing goal

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.