Acly / krita-ai-diffusion

Streamlined interface for generating images with AI in Krita. Inpaint and outpaint with optional text prompt, no tweaking required.
GNU General Public License v3.0
5.63k stars 252 forks source link

Give an option to have selection mask be applied to generated image #807

Open jacobEAdamson opened 3 weeks ago

jacobEAdamson commented 3 weeks ago

When inpainting an image with a selection mask, if the selection mask has semi-opaque parts, I'd like an option so that when applying the generated image, the selection mask's opacity is applied to the generated image. For example, if I have a selection mask with a feathered edge, I'd like the generated image layer (when accepting the result) to be feathered according to the selection mask. I usually get around this limitation by applying the selection mask as an opacity mask for the generated layer, but with the new region system, I would need to apply the selection mask as opacity mask to the layer generated in every single region. It would be nicer if I could automate this process.

Acly commented 3 weeks ago

It does work like that, kind of. The selection mask is taken into account (including transparency/feather), but it is split into denoising mask (>35% opacity) and alpha mask (below 35% opacity). The alpha mask is what you see applied to the layer, while the denoising mask is processed during generation and reduces the amount of change that happens to existing content according to the mask. #557 has more details.

In most cases blending denoising strength is superior to alpha blending.

jacobEAdamson commented 3 weeks ago

I find there's a noticeable difference in the alpha mask version vs the mix of alpha mask and denoising mask. Not to say the denoising mask is bad, but I tend to notice the edge more. Here's some examples. In the examples, I've turned off all feathering from the global settings, so only the selection mask's feathering is being used:

A freshly generated image, all of one piece:

krita_VNLzriAwbr

The same image where the selection area (without feathering, padding, or anything) has been regenerated. This one has a hard edge, which is expected because there's no feathering for the selection:

krita_ybGJxejDdq

The same image, but the selection mask has been feathered by 10 pixels, and the resulting inpainted image is applied without any other changes. Notice the area on the hand and the neck where you can see an edge:

krita_9GsJ0zE4cd

Finally, the same inpainted image is applied, but the original feathered selection mask is applied as an opacity layer on the generated layer:

krita_s9qDHJnKpt

I believe the last image is the best result, as it's much more difficult to see the "edge" of the inpainted selection on the neck and hand

jacobEAdamson commented 3 weeks ago

In addition, as you start inpainting at higher resolutions, the difference becomes more noticeable:

krita_cjBmxsgJNt krita_UXiNyh91bX