fix: getting rid of black borders in inpainting and img2img modes #29
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixing black borders in inpainting and img2img
found a bug causing black rectangles in inpainting and img2img. it happened because we weren't resizing images consistently. here's how i fixed it:
what i did
Image.resize()
instead of our old cropping orthumbnail()
stuffwhy i picked resizing
@andreas asked if we could crop to smaller multiples of 16 instead of resizing. i tried that and a bunch of other stuff:
thumbnail()
: saved memory, but results were inconsistent and sometimes looked badafter all that, i went back to
resize()
. it's not perfect (uses more memory, since it's a copy of the img), but it looked best and worked most consistently for all kinds of imagesthings i tried
did a ton of testing before settling on resizing. here's what i looked at:
thumbnail()
with different sampling methodseach had its own problems. some made images look worse, some couldn't get the size right, some added weird artifacts. resizing isn't perfect (uses more memory), but it worked best overall
test results
ran some tests to make sure the fix works. here's what happened:
these tests show my resizing approach works with different input sizes. it always gives output images that are multiples of 16 in both directions. the fix works for both img2img and inpainting, and it gets rid of the black border problem