ThereforeGames / unprompted

Templating language written for Stable Diffusion workflows. Available as an extension for the Automatic1111 WebUI.
777 stars 66 forks source link

Use of zoom_enhance with contour_padding in hires fix seems to result in stitched image chunks being offset from original: math error? #190

Closed Sporking closed 1 year ago

Sporking commented 1 year ago

Due diligence

Describe the bug

When I tried using "contour_padding" in txt2img mode, with hires fix enabled, and I was using zoom_enhance with 'debug' enabled, when I looked at the last debug output image in my WebUI folder, I saw stitching done in it, but the stitching was offset by some pixels (there was an almost transparent "ghost image" of the clipped regions overlaid and offset from my original source image). (I assume it was a ghost image rather than fully solid because I had specified a high "blur" setting.)

The pixel offset of the ghost versus the original looked suspiciously similar to my contour_padding size. When I removed the contour_padding setting, the offset disappeared, and the ghost image was overlaid directly on my original image as I expected. Perhaps the contour_padding value, when used with hires fix, needs to be scaled by the same amount that the hires fix scales, in order to work properly? Or some kind of offset needs to be applied (linear transformation) to make things line up properly? There seems to be a math error in how scaling of contour_padding is done with regards to hires fix.

Prompt

a pretty woman[after][zoom_enhance debug replacement="blue face" denoising_max=1 contour_padding=100][/after]

Hires Fix: resize from 512x512 to 1024x1024, Hires Steps: 20

Once image generation is done, look at last '...final_result' debug image in the WebUI folder. Observe that the stitched face is incorrectly offset approximately 100 pixels up and left of the face in the original image.

Log output

No response

Unprompted version

9.15.1

WebUI version

v1.5.1

Other comments

No response

ThereforeGames commented 1 year ago

Hi @Sporking,

Thank you for bringing this to my attention.

I have perhaps solved the countour_padding issue internally, but it will be a while before I push the next Unprompted patch (I'm in the process of getting it ready for the big 1.6.0 WebUI release.)

I'll attach the fixed file below if you'd like to try it early. Place it in unprompted/shortcodes/stable_diffusion and restart the UI. I tested it using your prompt with Hires. fix upscale values of 1.5, 2.0, 3.0 - in all cases the alignment seems to be okay now. Example:

zoom_enhance.zip

Let me know if it gives you any trouble. Thanks.

ThereforeGames commented 1 year ago

Fixed in v9.15.2.

Sporking commented 1 year ago

Thanks for fixing this!