feat(inpaint): add simpler infill methods for use with inpainting model

This commit is contained in:
Kevin Turner 2023-01-27 14:20:23 -08:00
parent c18db4e47b
commit d627cd1865

View File

@ -19,10 +19,13 @@ from ldm.util import debug_image
def infill_methods()->list[str]:
methods = list()
methods = [
"tile",
"solid",
"blur"
]
if PatchMatch.patchmatch_available():
methods.append('patchmatch')
methods.append('tile')
methods.insert(0, 'patchmatch')
return methods
class Inpaint(Img2Img):
@ -202,12 +205,22 @@ class Inpaint(Img2Img):
# Do infill
if infill_method == 'patchmatch' and PatchMatch.patchmatch_available():
init_filled = self.infill_patchmatch(self.pil_image.copy())
else: # if infill_method == 'tile': # Only two methods right now, so always use 'tile' if not patchmatch
elif infill_method == 'tile':
init_filled = self.tile_fill_missing(
self.pil_image.copy(),
seed = self.seed,
tile_size = tile_size
)
elif infill_method == 'solid':
solid_bg = PIL.Image.new("RGBA", init_image.size, (0x7F, 0x7F, 0x7F, 0xFF))
init_filled = PIL.Image.alpha_composite(solid_bg, init_image)
elif infill_method == 'blur':
solid_bg = PIL.Image.new("RGBA", init_image.size, (0x7F, 0x7F, 0x7F, 0xFF))
non_transparent = PIL.Image.alpha_composite(solid_bg, init_image)
blurred = non_transparent.copy().filter(ImageFilter.GaussianBlur(radius=mask_blur_radius))
init_filled = PIL.Image.alpha_composite(non_transparent, blurred)
else:
raise ValueError(f"Non-supported infill type {infill_method}", infill_method)
init_filled.paste(init_image, (0,0), init_image.split()[-1])
# Resize if requested for inpainting