How to remove unwanted objects in photos with AI inpainting

October 18, 2022

There’s an old post in Reddit showcasing a daunting tasks of removing the ex wife from a family photo. I surely can’t pull it off with my amateur Photoshop skill. But that was before the time of Stable Diffusion…. With democratization of AI image generation, would this be something that now anyone can do?

In this post, I am going to show you how use inpainting function of Stable Diffusion to remove object (a person in this case) and reconstruct the background.


We will use this Stable Diffusion GUI for this tutorial. See my quick start guide for setting up in Google’s cloud server.

What is inpainting?

Inpainting is a technqiue that Stable Diffusion only redraws part of an image. Specifically, you supply an image, draw a mask to tell which area of the image you would like it to redraw and supply prompt for the redraw. Stable Diffusion will redraw the masked area based on your prompt.

To access the inpainting function, go to img2img tab, and select the inpaint tab. Make sure the Draw mask option is selected. Upload the image to the canvas.


Adjust image size based on your original image. Because my image is in landscape orientation, I used size 768x512 pixels.

Select the batch size of 8 so that you can cherry pick the best image.

Let’s remove the ex wife…

OK, let’s get started. Since I don’t have access to the original image, I took a screenshot of the video and use as the input image:

Original image

In the GUI, draw a mask covering the area you want to erase and redraw. I’m starting with the main subject. My mask looks like this:

Original image with mask

Now supply the prompt of the background

photograph of a lake, tree, wooden deck, wooden fence

Press Generate. The inpainted image is

Inpainted ex

Not perfect but not too shabby! The deck floor and the legs are not quite right but we can fix them later. The deck fence is in a pretty good shape. Now let’s fix up the gentleman’s black pant and the floor.

photograph, pant, wooden deck

Inpainted ex

Fix the pant and floor one more time:

black pant, wooden deck

Inpainted ex

Now remove the long white dress behind the in-laws (?):

wooden deck, leg

Remove dress

Remove the word REMOVE and the arrow in the sky…

tree, sky

Remove arrow

It’s missing a deck board between the deck and the fence, let’s fix it.

wooden deck, lake

Fix transition deck and fence

Fix the gentleman’s arm…

lake, black jacket

Fix transition deck and fence

Finally, the deck floor the bride originally stood on is a bit unnatural. Let’s fix it.

wooden deck

Fix floor

Now are done! Let’s look at the before and the after side-by-side.

Fix transition deck and fence

I think it’s pretty good given we made less than 10 edits!


In this post, I showed you how easy it is to use inpainting to remove unwanted objects in a photo. What would have taken a professional Photoshop user hours can be done in fewer than 10 steps using inpainting with Stable Diffusion. I hope you too can use this powerful tool to accomplish what previously think only a professional can do!

Follow me on Twitter to receive content like this.

Subscribe to my newsletter to receive weekly updates.

Support me by using my products

You may also like:

How to come up with good prompts for AI image generation

How to fine-tune your AI images with these simple prompting techniques