Phase 08: Generative AI

Inpainting, Outpainting & Image Editing

Text-to-image makes new things. Inpainting fixes old ones. In production, 70% of billable image work is editing — swap a background, remove a logo, extend the canvas, regenerate a hand. Inpainting is where diffusion earns its keep. A client sends a perfect product photo with a distracting sign in the background. You want to erase the sign and leave everything else pixel-identical. You cannot run text-to-image from scratch — the result will have a different color, different lighting, different product angle. You want to regenerate only the masked region, and you want the regeneration to respect the surrounding context. That is inpainting. Variants: Inpainting. Regenerate inside a mask, keep outside pixels. Outpainting. Regenerate outside a mask (or beyond the canvas), keep inside. Image editing. Regenerate the whole image but keep semantic or structural fidelity to the original (SDEdit, InstructPix2Pix). Every diffusion pipeline in 2026 ships an inpainting mode. Flux.1-Fill, Stable Diffusion Inpaint, SDXL-Inpaint, DALL-E 3 Edit. They work on the same principle. Inpainting: mask-aware denoising with context-preserving reinjection Run standard text-to-image with a mask. At each sampling step, replace the unmasked region of the noisy latent with the forward-diffused clean image. It works... badly. Boundary artifacts bleed through because the model has no information about what is in the masked region. Train a modified U-Net that takes 9 input channels…

Inpainting, Outpainting & Image Editing: Text-to-image makes new things. Inpainting fixes old ones. In production, 70% of billable image work is editing —…

This free lesson is part of the AI Engineering from Scratch curriculum. Read the full explanation, run the lesson code, and verify the result in the interactive reader or from the repository source.

Browse the complete course catalog or open this lesson on GitHub.