-
Notifications
You must be signed in to change notification settings - Fork 27.1k
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
Split mask blur into X and Y components, patch Outpainting MK2 accordingly #10295
Split mask blur into X and Y components, patch Outpainting MK2 accordingly #10295
Conversation
This is a UI change and I don't even know what it fixes. Does user want to specify both X and Y blur normally? |
As stated above, it fixes a bug where outpainting to the left or right causes noise to appear at the bottom border (not near the outpainted region); is the bug not apparent from my screenshots?
I have no idea whether users want to do that, but if they do, it should be an easy modification on top of this PR. My motivation was just to fix the outpainting bug. |
Never mind, my bad, I didn't notice screenshots and misunderstood what this changes. StableDiffusionProcessingImg2Img should still accept |
OK, no worries, I'll re-add the |
Prequisite to fixing Outpainting MK2 mask blur bug.
Fixes unexpected noise in non-outpainted borders when using MK2 script.
a06616a
to
72815c0
Compare
PR updated to address review, sorry this took so long. |
Somehow, this commit broke tile/upscaling: Coyote-A/ultimate-upscale-for-automatic1111#111 |
Maybe, if some old code passes only |
Interesting, thanks for the heads up @dmzkrsk. I'll take a look and see if I maybe broke the defaults somehow. |
self.mask_blur = mask_blur | ||
if mask_blur is not None: | ||
mask_blur_x = mask_blur | ||
mask_blur_y = mask_blur | ||
self.mask_blur_x = mask_blur_x | ||
self.mask_blur_y = mask_blur_y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dmzkrsk As best I can tell, this section of code should prevent the failure mode you described. Do you see anything obviously wrong here?
@Splendide-Imaginarius FYI, this broke the ControlNet extension too, see my PR linked above. It was unknown for about 3 months. I did see you created a new branch here though -- do you still plan to open a PR for that here? |
Describe what this pull request is trying to achieve.
The mask blur in img2img was applied equally in both X and Y dimensions. This caused a bug in the Outpainting MK2 script, where noise would be introduced near borders other than the outpainted border. This PR splits out the mask blur into X and Y dimensions, which fixes the bad behavior.
Additional notes and description of your changes
PIL doesn't support applying a Gaussian blur in a single dimension, so I replaced PIL's Gaussian blur with that of OpenCV. I picked a kernel size that should be easily large enough to avoid quality issues; it may be a tad overkill but that shouldn't hurt anything.
I suspect that the bug will remain if you instruct MK2 to outpaint in more than one dimension at once, but that's not a regression, and AFAIK most users only outpaint in one direction at a time.
I didn't expose the new functionality to anything in the UI other than Outpainting MK2, but it should be easy for someone to do so if it's desired. (I couldn't think of a reason anyone would want this other than to fix the outpainting bug, but maybe I wasn't creative enough.)
Environment this was tested in
Screenshots or videos of your changes
Sample input image: https://github.com/Splendide-Imaginarius/stable-diffusion-webui/blob/mk2-blur-mask-docs/samples/original.png
Sample left-outpainted image without this PR: https://github.com/Splendide-Imaginarius/stable-diffusion-webui/blob/mk2-blur-mask-docs/samples/outpainted-broken.png
Sample left-outpainted image with this PR: https://github.com/Splendide-Imaginarius/stable-diffusion-webui/blob/mk2-blur-mask-docs/samples/outpainted-fixed.png
Note the noise along the bottom border of the outpainted image without this PR, and note that with this PR, the bottom border is the same as that of the input image.