Generative AI Beginner

Inpainting

Erasing part of a picture and filling it back in

Key points
  • Inpainting works inside a picture: you paint over the spot you want fixed, and the tool fills that spot back in.
  • What it fills with comes from the pattern and color around the spot. Anything you didn't paint stays untouched.
  • You can just erase, or write a sentence telling it what to put there instead.
  • The wider the painted spot, the harder the job gets. A small mark disappears cleanly, but a wide gap throws the pattern off.
  • Nothing original comes back. Something plausible gets made up in its place.
Contents

1The analogy

A torn patch of wallpaper doesn't send you re-papering the whole room. You cut out a bit more than the tear, match a new scrap to the same pattern, and press the seam flat until nobody can tell where you worked. Get the trim right and even a close look won't find the spot.

That's what inpainting does. Paint over the spot you want fixed in a photo, and it studies the pattern and color around that spot to fill the middle back in, the same way a steady hand reads a wallpaper roll before cutting.

The wider the cut, the harder the match gets. One small patch disappears cleanly, but tear out half the wall and the pattern drifts and the seam starts to show, no matter how carefully the new piece gets trimmed.

2In detail

Paint the spot to mark it

Open an inpainting tool and a photo comes with a brush. Only the painted area gets rebuilt; everything else stays exactly as it was. That painted area is called a mask — like punching a hole in a sheet of paper, laying it over the photo, and only touching what shows through the hole.

The trick is painting a little wider than you think you need. Trace an object's exact outline and you leave its shadow, its reflection on the floor, and the soft blur at its edge behind — enough of a trace that something's clearly missing.

Painting half the frame at once isn't a good idea either. The wider the area to fill, the fewer clues the surroundings give, and the more likely something odd shows up. Big objects come out cleaner erased in two or three passes than one.

It fills by reading what's around it

Filling works the same way a new picture gets made. The painted area turns to noise, and each step chips a little of that noise away until a shape appears. The difference is that at every step, the untouched area outside the mask gets pasted back in from the original. So the inside keeps checking itself against the outside the whole way through.

That's why backgrounds with a clear rule — brick joints, grass, ripples, tile grids — stitch back together beautifully. Backgrounds with no rule, or spots where several objects overlap, are harder to guess from the edges alone, and the results wobble.

You can tell it what to put there

Leave the sentence field blank and the tool just paves the spot over with background. That's the move for erasing a passerby or a stray wire from a photo.

Write a sentence and the story changes. Whatever you describe appears inside the painted spot — a potted plant, a new window, a different shirt color. It still gets shaped to match the light and shadow around it, which is why it reads far more natural than pasting in a cutout from another photo.

Keep the sentence to just what belongs in the painted spot. Describe the whole photo and the tool tries to redraw the surroundings too, and something odd ends up inside your mask. Want one window added? Write "window" and let the surroundings do the rest.

Why the seam shows

When a result looks off, it's usually the border giving it away — the filled spot too smooth, the focus slightly different, the light coming from the wrong direction. Photos shot in low light with a lot of grain make this gap stand out even more.

Repeating patterns are the other giveaway. A floor of tiles or a set of railings has a rhythm your eye already tracks, so if the filled section is off by even one tile, it jumps out immediately. Lining the painted edge up with the grid ahead of time helps a lot here.

The fix is simple: repaint a little wider around the border and run it again. The filled spot and its surroundings get rebuilt together, and the seam melts away. A few narrow passes beat trying to nail it in one shot.

3More precisely

Inpainting rebuilds only what the mask marks, pasting the original back over everything outside it at every step. That alone works well, but a model trained specifically on mask-plus-surroundings pairs blends the border even better. Some tools add a dial for how hard to rebuild — turn it down and a faint trace of the original shape survives; turn it up and something entirely new takes over.

The wallpaper comparison breaks in one spot. A real roll of wallpaper still has matching scraps left to cut, so what you paste really is the same pattern. Inpainting has no idea what used to be there — it invents something plausible with zero knowledge of the original. Something that was merely hidden can vanish and be replaced by something else entirely. And where a wallpaper patch keeps the same material as the rest of the roll, a filled spot can carry a slightly different focus or grain that shows up on close inspection. A real patch also stops changing once it's pressed flat, while a filled spot can come out slightly different every time the same masked photo gets run again.

4Try it yourself

5Common misconceptions

  • It's easy to think the erased spot comes back to what it originally looked like, but actually a plausible new scene gets built with no regard for whatever was hidden underneath.

  • It's easy to think painting tight to the outline is the accurate way to do it, but actually you need to cover the shadow and reflection generously too, or a trace gets left behind.

  • It's easy to think this is the same as background removal, but actually background removal cuts something out, while inpainting fills a gap back in.

7One-line summary

In shortInpainting rebuilds a painted-over spot to match the pattern around it, and the narrower and more often you touch it up, the less the seam shows.

Spotted an error or have a better analogy? Suggest an edit · Last updated2026-09-02