zavolokas / Inpainting

Want to remove something(someone) from a photo as it never was there? This is .NET implementation of content-aware fill. It smartly fills in unwanted or missing areas of photographs.
MIT License
368 stars 48 forks source link

Inpainting going outside of donor regions #41

Closed tylandercasper closed 4 years ago

tylandercasper commented 4 years ago

I'm using your project to generate textures from a 2D image, and I've noticed that a lot of the times it's pulling from regions outside of the donor list.

Since I'm only passing in the object to fill, this ends up creating shadows from the transparent regions. I'm attaching some sample data here:

BaseImage: base Delete Mask: delete Donor Mask: donor

Since the donor area doesn't contain any black, the ultimate result shouldn't contain any either, but it ends up looking like this: result

tylandercasper commented 4 years ago

Also great work! I love how you have it set up to show the progress while it's filling in the regions. It's an extremely impressive engine.

tylandercasper commented 4 years ago

I'm attaching another sample that gives a better appearance of how it's used. For visual purposes I replaced the white masks with the actual content that's being used for the donars and deletion:

Base image: base Delete Mask: delete Donor Mask: donor

Result: Result

I can understand if the black spot inbetween the two main floor boards is considered out of scope for what you're intending with the tool, but the blurred black around the edges and the big black spot on the right definitely an indicator that donor's aren't working quite right in general.

zavolokas commented 4 years ago

@tylandercasper thanks for the feedback! Currently there is no support for the semitransparent images.

tylandercasper commented 4 years ago

Well, even if I fill in the main image so the background is one color instead of clear (which I believe the program already does internally), it'll still draw from whatever the background is even though it's not in the donor region.

Here's an example with the background filled with pink. If it was exclusively using the donor region than it would then the entire section above would still be visible. Instead the background is used to fill in the center and the sides of the image,

pink

zavolokas commented 4 years ago

@tylandercasper I took a closer look at the markups. The essential part about the donor markup is that is should overlap with the area that you want to inpaint. The overlapping area needs to be inpainted using pixels from the part that doesn't overlap. Basically what you do that way is you are telling that this is one thing, but a part of it is missing, please reconstruct the missing part from the part that present.

Since your donor doesn't overlap with the area to inpaint, the algorithm doesn't know which parts you want to inpaint with these donors, so it uses the whole image.

zavolokas commented 4 years ago

Example:

tylandercasper commented 4 years ago

I did what you suggested and it looks a LOT better!

Thanks so much for your help!