{"course":{"slug":"making-things-with-ai","title":"Making Things with AI","url":"https://addaly.com/learn/making-things-with-ai","level":"beginner","track":"create"},"lesson":{"slug":"masks-and-inpainting","title":"Masks, feathering and the context window","url":"https://addaly.com/learn/making-things-with-ai/masks-and-inpainting","position":31,"of":84,"minutes":8,"answer":"Masked regeneration replaces only the masked latent while conditioning on the surrounding pixels, so what the model can see around the mask determines whether the repair matches.","keyIdea":"Masked regeneration replaces only the masked latent while conditioning on the surrounding pixels, so what the model can see around the mask determines whether the repair matches."},"body":{"format":"markdown","text":"## What a mask actually does\n\nInpainting is the same denoising loop with one addition. At every step, the parts of the latent outside your mask are overwritten with the correctly-noised version of the original image. Only the inside of the mask is free to change.\n\nThat means the region being regenerated is surrounded, at every step, by the real picture. The model is not repairing in isolation; it is completing a scene it can see. This is why inpainting produces results that match lighting and colour without being told to, and why it is a different and far more reliable tool than regenerating the whole image and hoping.\n\n## The three settings that decide the result\n\n**Mask size and shape.** Too tight and the model has no room to place anything; the fix is squeezed into an area the wrong shape. Too loose and you have thrown away good pixels. A useful default is to mask the problem plus roughly half its own width of surrounding area.\n\n**Feather or blur.** A hard-edged mask leaves a visible seam because the boundary between generated and original falls on a single pixel line. A feather of 4 to 16 pixels blends the transition. This one setting is the difference between a repair that reads and one that announces itself.\n\n**Context area: the setting nobody explains.** Most implementations do not process the whole image for an inpaint. They crop a region around the mask, scale it to the model's native size, generate, and paste back. The size of that crop is the model's entire view of the scene.\n\nThis last one explains the most common inpainting failure. Mask a face in a large image with a tight context crop, and the model sees a face-sized rectangle with no shoulders, no horizon and no light source. It has no idea which way the light falls, so it invents one. Widen the context and the same mask produces a correct result. In WebUI this appears as \"only masked padding\"; in ComfyUI it is the crop size on the inpaint node. When a repair comes back lit wrong, this is nearly always why.\n\n> Figure: One inpaint, and where the extra detail comes from. Steps: 1. Mask the problem, plus half its own width (A tight mask leaves no room to place anything. A feather of four to sixteen pixels stops the boundary landing on a single line of pixels and announcing itself.); 2. Crop a context area around it (This crop is the model's entire view of the scene. Too tight and it cannot see the light source, so it invents one, which is why a repair comes back lit wrong.); 3. Scale the crop up to the model's native size (A face worth seven latent cells in the whole picture now gets the whole grid. It is not trying harder; it has sixteen times the cells.); 4. Denoise, with the outside overwritten every step (Only the inside of the mask is free to change. The surrounding real pixels condition it at every step, which is why colour and lighting match without being described.); 5. Scale back and blend (The repair is pasted into the original through the feathered edge.). Outpainting is the same machinery pointed outwards: pad the canvas, mask the new area, and extend in steps of 128 or 256 pixels so each step still has context to hold on to.\n\n## Why the crop is also a resolution gift\n\nThere is a bonus in the crop mechanism worth exploiting deliberately. Because the cropped region is scaled up to the model's native size before generation, a small masked area is being generated at *full model resolution* and then scaled back down.\n\nA face that occupies seven latent cells in the full image occupies the whole latent grid when inpainted with a tight crop. This is the mechanism behind face-detailer workflows, and it is why inpainting a small element gives dramatically more detail than the same element in the original generation. It is not that the model tries harder. It has sixteen times the cells.\n\n## Outpainting is the same thing pointed outwards\n\nExtending an image beyond its borders uses identical machinery: pad the canvas, mask the new area, inpaint with the existing image as context. The failure modes are the same. Extend too far in one pass and the far edge has no context and drifts; extend in steps of 128 or 256 pixels and each step stays anchored.\n\nA practical note that saves a lot of confusion: many models are markedly worse at outpainting downward than in other directions, because photographs are cropped at the bottom far more consistently than at the top, so the training data contains fewer examples of what continues below a frame.\n\n## Where inpainting stops being the answer\n\nInpainting is the right tool for a wrong region. It is the wrong tool for a wrong picture. If the composition is not working, no amount of masked repair will fix it, and you will spend an hour discovering that.\n\nThere is also a class of problem inpainting handles badly: anything requiring agreement with a region you are not regenerating. Fixing one earring to match the other means the model must reproduce the other, which it can only see as context. It often gets close and rarely gets exact. For symmetry, the reliable fix is mechanical (copy the good one, flip it, place it, blend) in GIMP, Krita or Photopea, all free.\n\nThe general rule that emerges across this module: use the generative tool for texture and content, and use ordinary image editing for geometry and symmetry. Each is far better than the other at its own job, and most of the frustration people report comes from asking one to do the other's work."},"check":{"question":"An inpainted face comes back correctly rendered but lit from the wrong side. Which setting is the first thing to change?","options":[{"text":"The context crop around the mask, since the model can only match lighting it can actually see.","correct":true},{"text":"The mask feather, since a hard edge causes the lighting mismatch to appear at the boundary between regenerated and original pixels.","correct":false,"tempting":"Feathering controls how visible the seam is; it has no bearing on which direction the model believes the light comes from."},{"text":"The denoise strength, since a lower value would retain more of the original lighting inside the masked region.","correct":false,"tempting":"Lower strength retains the original pixels, which is the thing you were trying to replace; the lighting error would return with the face."},{"text":"The guidance scale, since higher guidance would make the model follow a lighting description in the prompt more closely.","correct":false,"tempting":"Prompting the light direction is a weak and unreliable substitute for letting the model see the surrounding scene."}]},"prev":{"slug":"denoise-strength","title":"Denoise strength: the number that decides how much survives","url":"https://addaly.com/learn/making-things-with-ai/denoise-strength"},"next":{"slug":"structural-conditioning","title":"Conditioning on structure: depth, edges and pose","url":"https://addaly.com/learn/making-things-with-ai/structural-conditioning"},"authorship":"Founder and series editor: Dr Mustafa Mun. Written by AI models to a written standard. Source and assessment review continues. Academic review invited.","review":{"status":"Draft, open for academic review"},"cite":"Addaly (2026) 'Masks, feathering and the context window', in Making Things with AI. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/making-things-with-ai/masks-and-inpainting (Accessed: 29 November 2026).","licence":{"name":"CC BY-NC-SA 4.0","url":"https://creativecommons.org/licenses/by-nc-sa/4.0/"},"reader":{"schema":1,"title":"Masks, feathering and the context window","courseTitle":"Making Things with AI","module":{"index":4,"slug":"control-not-luck","title":"Control: getting the picture you actually need"},"answer":null,"keyIdea":"Masked regeneration replaces only the masked latent while conditioning on the surrounding pixels, so what the model can see around the mask determines whether the repair matches.","hero":{"kind":"figure","figure":{"t":"figure","label":"Figure","figure":{"caption":"Outpainting is the same machinery pointed outwards: pad the canvas, mask the new area, and extend in steps of 128 or 256 pixels so each step still has context to hold on to.","steps":[{"label":"Mask the problem, plus half its own width","detail":"A tight mask leaves no room to place anything. A feather of four to sixteen pixels stops the boundary landing on a single line of pixels and announcing itself."},{"label":"Crop a context area around it","detail":"This crop is the model’s entire view of the scene. Too tight and it cannot see the light source, so it invents one, which is why a repair comes back lit wrong."},{"label":"Scale the crop up to the model’s native size","detail":"A face worth seven latent cells in the whole picture now gets the whole grid. It is not trying harder; it has sixteen times the cells."},{"label":"Denoise, with the outside overwritten every step","detail":"Only the inside of the mask is free to change. The surrounding real pixels condition it at every step, which is why colour and lighting match without being described."},{"label":"Scale back and blend","detail":"The repair is pasted into the original through the feathered edge."}],"title":"One inpaint, and where the extra detail comes from","type":"flow"},"alt":"Figure: One inpaint, and where the extra detail comes from. Steps: 1. Mask the problem, plus half its own width (A tight mask leaves no room to place anything. A feather of four to sixteen pixels stops the boundary landing on a single line of pixels and announcing itself.); 2. Crop a context area around it (This crop is the model’s entire view of the scene. Too tight and it cannot see the light source, so it invents one, which is why a repair comes back lit wrong.); 3. Scale the crop up to the model’s native size (A face worth seven latent cells in the whole picture now gets the whole grid. It is not trying harder; it has sixteen times the cells.); 4. Denoise, with the outside overwritten every step (Only the inside of the mask is free to change. The surrounding real pixels condition it at every step, which is why colour and lighting match without being described.); 5. Scale back and blend (The repair is pasted into the original through the feathered edge.). Outpainting is the same machinery pointed outwards: pad the canvas, mask the new area, and extend in steps of 128 or 256 pixels so each step still has context to hold on to."}},"blocks":[{"t":"h2","id":"what-a-mask-actually-does","runs":[{"text":"What a mask actually does"}]},{"t":"p","runs":[{"text":"Inpainting is the same denoising loop with one addition. At every step, the parts of the latent outside your mask are overwritten with the correctly-noised version of the original image. Only the inside of the mask is free to change."}]},{"t":"p","runs":[{"text":"That means the region being regenerated is surrounded, at every step, by the real picture. The model is not repairing in isolation; it is completing a scene it can see. This is why inpainting produces results that match lighting and colour without being told to, and why it is a different and far more reliable tool than regenerating the whole image and hoping."}]},{"t":"h2","id":"the-three-settings-that-decide-the-result","runs":[{"text":"The three settings that decide the result"}]},{"t":"p","runs":[{"text":"Mask size and shape.","b":true},{"text":" Too tight and the model has no room to place anything; the fix is squeezed into an area the wrong shape. Too loose and you have thrown away good pixels. A useful default is to mask the problem plus roughly half its own width of surrounding area."}]},{"t":"p","runs":[{"text":"Feather or blur.","b":true},{"text":" A hard-edged mask leaves a visible seam because the boundary between generated and original falls on a single pixel line. A feather of 4 to 16 pixels blends the transition. This one setting is the difference between a repair that reads and one that announces itself."}]},{"t":"p","runs":[{"text":"Context area: the setting nobody explains.","b":true},{"text":" Most implementations do not process the whole image for an inpaint. They crop a region around the mask, scale it to the model’s native size, generate, and paste back. The size of that crop is the model’s entire view of the scene."}]},{"t":"p","runs":[{"text":"This last one explains the most common inpainting failure. Mask a face in a large image with a tight context crop, and the model sees a face-sized rectangle with no shoulders, no horizon and no light source. It has no idea which way the light falls, so it invents one. Widen the context and the same mask produces a correct result. In WebUI this appears as “only masked padding”; in ComfyUI it is the crop size on the inpaint node. When a repair comes back lit wrong, this is nearly always why."}]},{"t":"h2","id":"why-the-crop-is-also-a-resolution-gift","runs":[{"text":"Why the crop is also a resolution gift"}]},{"t":"p","runs":[{"text":"There is a bonus in the crop mechanism worth exploiting deliberately. Because the cropped region is scaled up to the model’s native size before generation, a small masked area is being generated at "},{"text":"full model resolution","i":true},{"text":" and then scaled back down."}]},{"t":"p","runs":[{"text":"A face that occupies seven latent cells in the full image occupies the whole latent grid when inpainted with a tight crop. This is the mechanism behind face-detailer workflows, and it is why inpainting a small element gives dramatically more detail than the same element in the original generation. It is not that the model tries harder. It has sixteen times the cells."}]},{"t":"h2","id":"outpainting-is-the-same-thing-pointed-outwards","runs":[{"text":"Outpainting is the same thing pointed outwards"}]},{"t":"p","runs":[{"text":"Extending an image beyond its borders uses identical machinery: pad the canvas, mask the new area, inpaint with the existing image as context. The failure modes are the same. Extend too far in one pass and the far edge has no context and drifts; extend in steps of 128 or 256 pixels and each step stays anchored."}]},{"t":"p","runs":[{"text":"A practical note that saves a lot of confusion: many models are markedly worse at outpainting downward than in other directions, because photographs are cropped at the bottom far more consistently than at the top, so the training data contains fewer examples of what continues below a frame."}]},{"t":"h2","id":"where-inpainting-stops-being-the-answer","runs":[{"text":"Where inpainting stops being the answer"}]},{"t":"p","runs":[{"text":"Inpainting is the right tool for a wrong region. It is the wrong tool for a wrong picture. If the composition is not working, no amount of masked repair will fix it, and you will spend an hour discovering that."}]},{"t":"p","runs":[{"text":"There is also a class of problem inpainting handles badly: anything requiring agreement with a region you are not regenerating. Fixing one earring to match the other means the model must reproduce the other, which it can only see as context. It often gets close and rarely gets exact. For symmetry, the reliable fix is mechanical (copy the good one, flip it, place it, blend) in GIMP, Krita or Photopea, all free."}]},{"t":"p","runs":[{"text":"The general rule that emerges across this module: use the generative tool for texture and content, and use ordinary image editing for geometry and symmetry. Each is far better than the other at its own job, and most of the frustration people report comes from asking one to do the other’s work."}]}],"check":{"question":[{"text":"An inpainted face comes back correctly rendered but lit from the wrong side. Which setting is the first thing to change?"}],"options":[{"text":[{"text":"The context crop around the mask, since the model can only match lighting it can actually see."}],"correct":true,"tempting":null},{"text":[{"text":"The mask feather, since a hard edge causes the lighting mismatch to appear at the boundary between regenerated and original pixels."}],"correct":false,"tempting":[{"text":"Feathering controls how visible the seam is; it has no bearing on which direction the model believes the light comes from."}]},{"text":[{"text":"The denoise strength, since a lower value would retain more of the original lighting inside the masked region."}],"correct":false,"tempting":[{"text":"Lower strength retains the original pixels, which is the thing you were trying to replace; the lighting error would return with the face."}]},{"text":[{"text":"The guidance scale, since higher guidance would make the model follow a lighting description in the prompt more closely."}],"correct":false,"tempting":[{"text":"Prompting the light direction is a weak and unreliable substitute for letting the model see the surrounding scene."}]}],"order":[3,1,0,2],"why":null},"prev":{"slug":"denoise-strength","title":"Denoise strength: the number that decides how much survives","minutes":8},"next":{"slug":"structural-conditioning","title":"Conditioning on structure: depth, edges and pose","minutes":9}}}