omerbt / MultiDiffusion

Official Pytorch Implementation for "MultiDiffusion: Fusing Diffusion Paths for Controlled Image Generation" presenting "MultiDiffusion" (ICML 2023)
https://multidiffusion.github.io/
979 stars 57 forks source link

fixed illusion.py center_crop_resize to handle non-square outputs #27

Closed dribnet closed 11 months ago

dribnet commented 11 months ago

The example pano_pattern.png that illusion.py uses by default looks like this

pano_pattern

When I ran the script, I got output that didn't match that pattern exactly

ill_oldbad

A bit of investigation showed that my output had been based instead on this stretched version of the controlnet image - which it does match:

crop2

Which is what happens if you take a square center crop of the original controlnet image:

crop1

and then just stretch it to cover the target rectangle. This is what the logic of the center_crop_resize seemed to be doing - likely because the upstream code didn't expect to need to handle non-square outputs. I updated this logic to instead take the aspect ratios of the source and destination into account and instead use the largest center crop possible for non-square outputs.

After this change I get output that matches my expectations for the original controlnet image

ill9

And also tested it on a sideways version of this image and to check that the logic seems to work as planned for tall images too

ill_tall1

omerbt commented 11 months ago

Good catch!