liveBook · Manning

Inpainting

As explained in Deep Learning with PyTorch, Second Edition

An image-generation/editing technique that fills in masked regions of an input image using a model and conditioning prompt.

Inpainting fills a selected region of an image while preserving the rest. A text prompt describes the desired change, and a mask acts as a digital stencil: white pixels are editable, while black pixels remain protected. section 2.2 section 2.2.1

Diffusion models perform the edit through iterative denoising. The input image anchors the composition, the prompt guides the result, and the mask constrains changes to the selected region by reinserting unmasked content during restoration. section 2.2.1

A practical inpainting workflow uses a pretrained pipeline:

  • Load an inpainting pipeline and move it to an available device. section 2.2.2
  • Provide the source image, mask image, descriptive prompt, and optional negative prompt. section 2.2.2
  • Adjust generation controls such as guidance scale and strength, then inspect the generated image. section 2.2.2

Turning a horse into a zebra

A horse photograph, a mask over the horse, and the prompt “a zebra replacing the original horse, same pose, same lighting, background unchanged” produce a localized attempted zebra edit while retaining the surrounding scene. section 2.2.1 section 2.2.2

Figure 2.5 The model inputs
figure

Shows the image, mask, and prompt as the model inputs that jointly control an inpainting edit. section 2.2.1

Figure 2.6 A diffusion model gradually processing an image
figure

Visualizes successive denoising stages as a masked image becomes a blended edited result. section 2.2.1

How Deep Learning with PyTorch, Second Edition covers it

How deep it goes
Explains mask locality and iterative denoising, then demonstrates pipeline invocation while deferring diffusion internals.
Examples
Demonstrates replacing a masked horse with a zebra using an image, mask, prompt, negative prompt, and pipeline call.
What it assumes
Assumes basic image and pretrained-model familiarity while teaching the prompt, image, mask, and denoising roles directly.
What you can do after
Operate a pretrained Diffusers inpainting pipeline with images, masks, prompts, and generation settings.
How it connects
Connects diffusion models, image-to-image generation, pretrained networks, inference, text prompts, and image masks.

Also explained in

Compare how 3 books explain inpainting →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with PyTorch, Second Edition. The section links point to the parts of the book it draws on.