{"id":5380,"date":"2026-03-10T07:10:23","date_gmt":"2026-03-10T11:10:23","guid":{"rendered":"https:\/\/dft.wiki\/?p=5380"},"modified":"2026-03-10T20:46:02","modified_gmt":"2026-03-11T00:46:02","slug":"ai-image-transformation-inpainting","status":"publish","type":"post","link":"https:\/\/dft.wiki\/?p=5380","title":{"rendered":"AI Image Transformation &#8211; Inpainting \/ Outpainting"},"content":{"rendered":"<p><strong>INPAINTING<\/strong><\/p>\n<p>Inpainting is a technique used to modify specific parts of an image. It uses a <strong>mask<\/strong> to define the editable area, ensuring the rest of the image remains exactly the same. For example, you can use it to change a person&#8217;s expression or swap an object in a scene.<\/p>\n<p>Since the process requires both the original image and the mask, both are loaded and passed to the specialized inpainting pipeline:<\/p>\n<pre>from diffusers import AutoPipelineForInpainting\r\nfrom diffusers.utils import load_image\r\n\r\npipeline = AutoPipelineForInpainting.from_pretrained(\r\n    \"<strong>stable-diffusion-v1-5\/stable-diffusion-inpainting<\/strong>\",\r\n)\r\n\r\nprompt = \"<strong>bride running<\/strong>\"\r\nimage = pipeline(\r\n    prompt=prompt,\r\n    image=load_image(\"<strong>girl.png<\/strong>\"),\r\n    mask_image=load_image(\"<strong>mask.png<\/strong>\").convert(\"L\"),\r\n).images[0]\r\n\r\nimage.save(\"<strong>output.png<\/strong>\")\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5370\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/bride.png\" alt=\"\" width=\"768\" height=\"256\" srcset=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/bride.png 768w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/bride-300x100.png 300w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/p>\n<p>To achieve a smoother transition between the modified pixels and the original background, you can apply a blur to the mask before processing:<\/p>\n<pre><strong>mask_image<\/strong> = load_image(\"mask.png\")\r\n<strong>blurred_mask<\/strong> = pipeline.mask_processor.blur(mask_image, blur_factor=33)<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5374\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/cat.png\" alt=\"\" width=\"768\" height=\"256\" srcset=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/cat.png 768w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/cat-300x100.png 300w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/p>\n<p><strong>OUTPAINTING<\/strong><\/p>\n<p>Outpainting extends the image beyond its original boundaries. Technically, this is achieved by using the Inpainting pipeline with an <strong>inverted mask<\/strong> (where the &#8220;hole&#8221; is the area outside the original content).<\/p>\n<pre>from PIL import ImageOps\r\n\r\n<strong>mask_image<\/strong> = load_image(\"<strong>mask.png<\/strong>\").convert(\"L\")\r\nmask_image = ImageOps.<strong>invert<\/strong>(<strong>mask_image<\/strong>)<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5387\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/1773170975_01_0_50_0.99_9.9_grid.png\" alt=\"\" width=\"768\" height=\"256\" srcset=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/1773170975_01_0_50_0.99_9.9_grid.png 768w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/1773170975_01_0_50_0.99_9.9_grid-300x100.png 300w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/p>\n<p>For more details and reference, see my own code used to generate the images above at <strong>Inpainting<\/strong> [<a href=\"https:\/\/github.com\/davift\/Inpainting\">Link<\/a>].<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5376\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/Screenshot_2026-03-09_21-28-31.png\" alt=\"\" width=\"1233\" height=\"910\" srcset=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/Screenshot_2026-03-09_21-28-31.png 1233w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/Screenshot_2026-03-09_21-28-31-300x221.png 300w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/Screenshot_2026-03-09_21-28-31-1024x756.png 1024w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/Screenshot_2026-03-09_21-28-31-768x567.png 768w\" sizes=\"auto, (max-width: 1233px) 100vw, 1233px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>INPAINTING Inpainting is a technique used to modify specific parts of an image. It uses [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-5380","post","type-post","status-publish","format-standard","hentry","category-ai"],"_links":{"self":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/5380","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5380"}],"version-history":[{"count":4,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/5380\/revisions"}],"predecessor-version":[{"id":5406,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/5380\/revisions\/5406"}],"wp:attachment":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}