adapt outcrop.py to use new outpainting code

- unfortunately it does not look as good as the old code
  which just used plain inpainting.
This commit is contained in:
Lincoln Stein 2022-10-31 00:20:53 -04:00
parent 2b39d1677c
commit 582fee6c3a

View File

@ -42,6 +42,9 @@ class Outcrop(object):
init_img = extended_image,
strength = opt.strength,
image_callback = wrapped_callback,
seam_size = 32,
seam_blur = 10,
force_outpaint = True, # this just stops the warning about erased regions
)
# swap sampler back
@ -89,26 +92,12 @@ class Outcrop(object):
def _extend(self,image:Image,pixels:int)-> Image:
extended_img = Image.new('RGBA',(image.width,image.height+pixels))
mask_height = pixels if self.generate.model.model.conditioning_key in ('hybrid','concat') \
else pixels *2
# first paste places old image at top of extended image, stretch
# it, and applies a gaussian blur to it
# take the top half region, stretch and paste it
top_slice = image.crop(box=(0,0,image.width,pixels//2))
top_slice = top_slice.resize((image.width,pixels))
extended_img.paste(top_slice,box=(0,0))
# second paste creates a copy of the image displaced pixels downward;
# The overall effect is to create a blurred duplicate of the top portion of
# the image.
extended_img.paste((0,0,0),[0,0,image.width,image.height+pixels])
extended_img.paste(image,box=(0,pixels))
extended_img = extended_img.filter(filter=ImageFilter.GaussianBlur(radius=pixels//2))
extended_img.paste(image,box=(0,pixels))
# now make the top part transparent to use as a mask
alpha = extended_img.getchannel('A')
alpha.paste(0,(0,0,extended_img.width,mask_height))
alpha.paste(0,(0,0,extended_img.width,pixels))
extended_img.putalpha(alpha)
return extended_img