Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: txt2img outpainting feathering/mask blur #1811

Closed
catboxanon opened this issue Jul 21, 2023 · 1 comment · Fixed by #1813
Closed

[Feature]: txt2img outpainting feathering/mask blur #1811

catboxanon opened this issue Jul 21, 2023 · 1 comment · Fixed by #1813

Comments

@catboxanon
Copy link
Contributor

catboxanon commented Jul 21, 2023

See #1597 (comment) for background.

txt2img outpainting currently still produces a visible seam if you look closely enough. Depending on the image this can be more or less obvious in some cases. The solution here is also not ideal because it's still a hard cut off, it still fails in some cases, and removes more of the original image that would be kept if feathering were used. The simplest method I see to work around this is employ a feathering technique, like the one already implemented in the webui's img2img inpaint functionality.

The idea would be to allow the inpainted area to be slightly larger by a given amount, as to replace part of the original image, but before the result is returned to the user, the original image would be composited (or "overlaid") on top and have the edges feathered by that same given amount. This is essentially the same thing the webui does for it's inpaint implementation from my understanding.

https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/f865d3e11647dfd6c7b2cdf90dde24680e58acd8/modules/processing.py#L1196-L1206
https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/f865d3e11647dfd6c7b2cdf90dde24680e58acd8/modules/img2img.py#L117-L125

I plan to try implementing and opening a PR for this myself, but if this issue remains dormant for a few days you can safely assume I did not succeed in my attempt. 😅

@catboxanon
Copy link
Contributor Author

catboxanon commented Jul 21, 2023

While working on this I actually now notice the current implementation is already supposed to be doing something similar, just linking here for posterity.

sigma = 7
final_inpaint_mask = cv2.dilate(final_inpaint_mask, np.ones((sigma, sigma), dtype=np.uint8))
final_inpaint_mask = cv2.blur(final_inpaint_mask, (sigma, sigma))[None]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant