← Back to Advent of Code

Day 8 - Extending day 3's work - using Nano Banana Pro to inpaint and repair any gaps in segmented images

12/08/25

I spent today extending the concept I was working on in Day 3 . Read the short writeup on that day first for some context.

It's common that the subject you lift from the original will have gaps or tears in the segmented image, because the subject was partially occluded in the original image. For example:

Original image
Original
"person"
Segmented result
Result (note the dog-shaped hole)

So I simply pass the segmented image to Nano Banana Pro to inpaint and repair, while preserving the transparency of the segmentation.

Segmented with hole
Segmented (with dog-shaped hole)
✨ Inpaint
Inpainted result
Inpainted

The exact method to preserve this transparency took a bit of meandering to work out, but ultimately settled on an approach where Gemini will put the inpainted image on a white background, and we create a transparency mask that marks pixels as transparent if it was a white background pixel AND if it was transparent in the original segmentation image. This produced the cleanest results in my short testing, but it's likely there are edge cases where this approach will fail, and I'm sure there are more effective methods out there. But this is satisfactory for now. cases where this approach will fail). But this is satisfactory for now. Try it out below! It's the same UI as Day 3, but this time, you'll also have the option to "Inpaint" the segmented image.

Try it yourself!

Drop image or click to select