---
title: "Inpainting: How Masked Areas Get Filled - CE.SDK Glossary"
description: "Inpainting fills a masked area of an image to match the rest. See how classical and AI methods work, what mask settings do, and why CE.SDK designs need it less."
url: "https://img.ly/glossary/inpainting/"
type: "page"
---

> This is the markdown version of [Inpainting: How Masked Areas Get Filled - CE.SDK Glossary](https://img.ly/glossary/inpainting/). For all pages in one file, see [llms-full.txt](https://img.ly/llms-full.txt). For an index of all available pages, see [llms.txt](https://img.ly/llms.txt).

---

# Inpainting

## What Is Inpainting?

Inpainting fills in an area of an image that is missing, damaged or masked, using content that matches what surrounds it. The word comes from art restoration, where conservators repaint the damaged areas of a painting, and image software took it over for repairing scratches, dust and tears in photos.

In AI tools, you brush a mask onto the area, with white marking the pixels to fill and black the pixels to keep, and you can add a prompt describing what belongs there. People use it to remove objects, text and date stamps, to repair old photos, and to redo a hand or a face that came out wrong.

## How Does Inpainting Work?

Methods have moved from reusing the image's own pixels to generating new ones, and the older ones still suit small repairs.

1. **Spreading color in from the edges** (Best on thin scratches): Early digital methods, modeled on how conservators restore paintings, carry the colors and lines at the border of the gap inward. Researchers call them diffusion-based. They work well on scratches and other thin gaps, but anything wider comes out blurred.

2. **Copying patches from the same image** (Best on grass, sand and brick): Exemplar-based methods, such as one Microsoft Research published in 2003, search the photo for small patches that match the area around the gap and copy the best match in, working from the edges inward so lines carry through. They handle grass, sand and brick well, but they can only reuse what the photo already contains.

3. **Neural networks trained on photos** (Copes with larger gaps): Deep learning models learn from example photos what belongs in a hole. Partial convolutions, introduced in 2018, read only the valid pixels, so the empty area's color doesn't leak into the fill. In IMG.LY's 2020 tests, a GAN-based network rebuilt the grid of a metal door hidden behind a person, where the partial-convolution network it was compared with painted the area a uniform black. LaMa, from 2021, was trained on large masks and copes with big gaps and higher resolutions.

4. **Diffusion models that generate from noise** (Follows a text prompt): These fill the mask with noise and remove it step by step, putting the unmasked pixels back after every step so the new content keeps fitting them. In Stable Diffusion inpainting, a prompt steers what appears. Despite the name, they have nothing to do with the diffusion-based methods above, since here the word refers to adding and removing noise.

## What Do Inpainting Mask Settings Do?

AI inpainting tools share a handful of controls, though each tool names them its own way. The names below are the ones Stable Diffusion tools use.

- **Mask blur**: What it controls: How soft the edge of the mask is, When to change it: Raise it when a seam shows, but too much lets the fill alter pixels you meant to keep

- **Strength**: What it controls: How far the fill may move from the pixels under the mask, When to change it: Low to recolor or retouch, high to put something new there

- **Only masked area**: What it controls: Fills a crop around the mask at the model's full size, When to change it: Turn it on for small areas such as faces, which come out sharper

## Why Do Large Masks Give Weaker Inpainting Results?

IMG.LY ran into two limits in 2020 while testing inpainting networks on high-resolution photos with the Bochumer Institute of Technology.

### The middle of a large mask is far from real pixels

A model fills a hole from what borders it, so quality drops toward the center of a big mask, where the nearest real pixels are farthest away. The [2020 tests](https://img.ly/blog/image-inpainting.md) countered this by filling in rounds, shrinking the mask from its edge toward the center each time. The fill looked better for it, though every round ran the network again and added computing time.

### Models work at one fixed size

One of the networks in those tests was trained at 512 × 680 pixels, so a much larger photo had to be scaled down, filled and scaled back up, which softened the result. Small masks on large photos still came out well, and the only-masked setting above works on the same principle.

## How Layered Editing Works in CE.SDK

In a CE.SDK design, text, logos and photos are separate blocks, so a change to one of them leaves the pixels of the others alone.

### Step 01: Edit text and logos as blocks

A headline is a text block and a logo is its own image, so your users retype a line or swap a logo without a mask or a model call, and the type stays sharp. In IMG.LY's [test of a layered AI ad](https://img.ly/blog/edit-ai-output-without-regenerating.md), swapping the logo took 10 milliseconds.

### Step 02: Cut the background off a photo

On the web, the [background removal plugin](https://img.ly/glossary/background-removal-plugin.md) cuts the subject from a photo inside the browser, so the image never leaves the device. The cutout sits over whatever background the design uses, and moving it leaves no hole to fill.

### Step 03: Regenerate one image and keep the rest

When one photo needs new pixels, your users send only that block to an [image-to-image](https://img.ly/use-cases/ai-editor/image-to-image.md) model, and every other block stays exactly as it was. In the same test, regenerating only the background took 38 seconds and left the headline, product and logo as they were, while regenerating the whole ad as one image changed the product, logo and layout from one attempt to the next.

## FAQs

### Inpainting

**Q: How is inpainting different from outpainting?**

A: Inpainting fills an area inside the image, with real pixels on every side to match. Outpainting adds new area past the original edges, so the model has to extend the scene from context on one side only.

**Q: Is inpainting the same as generative fill?**

A: No. Generative fill is a name for prompt-driven inpainting that Adobe introduced in Photoshop in 2023.

**Q: Why do some inpainting tools paste the original pixels back?**

A: Models trained for inpainting blend the fill into its surroundings more naturally, but they are also more likely to alter pixels outside the mask. Pasting the original unmasked pixels back on top keeps them untouched, though the edge around the fill can then look harder.

**Q: Can you inpaint without painting a mask?**

A: Yes. Segmentation models such as Segment Anything draw the mask when you click an object, and tools like CLIPSeg build one from a text description. Instruction-based editing skips the mask altogether, as when your users add or remove objects by describing them.

## Links

- [Add & Remove Objects](https://img.ly/use-cases/ai-editor/add-remove-objects.md): Let users change what is in a photo by describing it, with no mask.
- [Image to Image](https://img.ly/use-cases/ai-editor/image-to-image.md): Regenerate one image block from a prompt.
- [Remove Background on the Web](https://img.ly/docs/cesdk/js/edit-image/remove-bg-9dfcf7.md): Remove a photo's background in the browser with the plugin.

---

## More Resources

- **[IMG.LY Website](https://img.ly/index.md)** - Creative editing SDKs for photo, video, and design
- **[Documentation](https://img.ly/docs/cesdk/)** - CE.SDK developer documentation
- **[Build with a coding agent](https://img.ly/SKILL.md)** - A skill that adds a CE.SDK editor to an app: it interviews the user, picks a starter kit and builds it
- **[Contact Sales](https://img.ly/forms/contact-sales.md)** - Get a custom quote. A public JSON API accepts the request directly, no account or key needed. Ask your user for consent and their details first.
- **[Free Trial](https://img.ly/pricing.md)** - Start building with CE.SDK
