I've made an Extension "Disable Inpainting Overlay"! #11612
aleksusklim
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Here is the repo: https://github.com/klimaleksus/stable-diffusion-webui-disable-inpainting-overlay
My extension can solve 3 rare inpainting problems, each with its own checkbox!
First: "Disable inpainting overlay"
How often do you use inpainting solely to copy its result to your favorite layered image editor? So that you can erase everything except the target area manually?
If so, didn't you feel limited by the border? That border, which was blurred by the mask. How often did you try to pick-up a good value of "Mask blur" that will work for you?
Did you notice that sometimes, no matter how hard you try, the inpainted result still has the visible seam? You want to get rid of it by cleaning your top layer, but the border is so thin…
"Disable Inpainting Overlay" extension can solve this!
It will prevent WebUI from applying the masked composite of the source to your final image. It's like having no border whatsoever!
However, without automatic composition and overlaying, you have to do the composition yourself.
You should NOT use the result of such inpainting without manual clean-up!
Thing is, all unmasked pixels are still going through VAE, which compresses and decompresses them.
With normal inpainting, WebUI discards the compressed result on unmasked areas. But my method leaves you with fully compressed image.
If you would use this as-is, sending it back to input again – it will compress the image further with the next step, corrupting your picture! It is like converting JPEG to JPEG over and over again.
If you wonder how iterative VAE compression looks like, watch it here:
vae2vae.mp4
So, try "Disable inpainting overlay" checkbox when you are planning to add the inpainted result as a layer that you will clean and erase by yourself.
Second: "Align mask on VAE squares"
How often did you use the resulting image, sending it back to input without changing the mask?
Have you noticed that after several iterations, the border around that mask become blurry? Like it accumulated all previous used pictures, instead of re-inpainting them completely from scratch?
That is because on semi-transparent areas of the mask, WebUI composites your input image. Which means that each time, those pixels are "inpainted partially" and never completely replaced
After many output-to-input cycles, such regions will contain some kind of overlapping everything that you saw so far.
The only way to get rid of it – is to enlarge the mask each time you re-inpaint the same area.
While the previous option of my extension can solve this, it requires you to edit the layer each time manually (you should NOT send the result back to input as-is!)
Another way to undo the side-effect of mask transparency – is to get rid of transparency altogether, and you can do that at any time.
However, mask composition will lie to you: thing is, your mask is downscaled by 8 times and then rounded (binarized) to pure black-and-white. Original semi-transparent mask is used later, only to overlay with your source image. Actual diffusion process operates by blocks of 8x8 pixels!
This option makes your mask fit exactly these 8x8 blocks, with only two colors without any transparency. You blurring is still applied, but before my own rounding and aligning. (Technically, the actual mask might be slightly larger with my method, because I consider any square with at least one white pixel as completely masked).
Now you can be sure that iterative inpainting will not leave any traces of previous results! But your seam will be… you know, very visible. Because there is no transparency that hides this fact from you anymore.
There is no sense to apply both methods (aligning the mask and disabling overlay) at the same time, because just disabling the overlay will be already enough to negate the effects of semi-transparent areas.
So, if you plan to inpaint the same area several times (especially at high denoising strengths), check "Align mask on VAE squares". Don't worry, those edges will be destroyed by your next inpainting!
As the last step, you could either disable the overlay completely, or just enlarge the mask (and uncheck this) – to inpaint your area the final time.
Third: "Ignore padding but crop to 1:1 resolution"
How often did you use "Only masked" inpaint area, but failed to pick-up a perfect padding for it? How on Earth would you calculate the desired image size to inpaint only area you want?
Have you though that just cropping the image manually is way simpler and cleaner than to use "Only masked" (formerly "Inpaint at full resolution")?
Don't you think that pre-upscaling your image before inpainting – is better than inpaint one area at high-resolution just to downscale it back?
How do you change the upscale ratio, if you could only play with padding and target resolution, which choses the scaling implicitly?
Did you want to say, "Hey, can you please crop at 640x512 around my mask, but do not change the resolution, since my image is already upscaled"?
That is exactly what this option will do!
It will ignore your "Only masked padding, pixels" value, recalculating the padding by width and height separately. So your masked area will be always at the center of the cropped window.
Inpainting will be applied at the same resolution that your input image has. You won't get more details, you're not gonna lose details (when your mask is wider that the crop – but here some parts of the mask will be dropped instead).
The only options that you still can choose – is your target crop dimensions. But now, the masked area won't be upscaled to fit that, but just automatically padded as much as it can, without upscaling anything.
When you are working with already upscaled image (which you should do, at later steps of your refining), check "Ignore padding but crop 1:1" and save time, because you can mask anything you want with the same relative quality!
You can use this together with disabling the overlay (first checkbox), so that you'll see exactly the area you're working at. The second checkbox also could be used if you want.
Just make sure that your source image is not less than your selected width and height!
Beta Was this translation helpful? Give feedback.
All reactions