mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(inpaint): add solid infill for use with inpainting model (#2441)
A new infill method, **solid:** solid color. currently using middle gray. Fixes #2417 It seems like the runwayml inpainting model specifically expects those masked areas to be blanked out like this. I haven't tried the SD 2.0 inpainting model with it yet.
This commit is contained in:
commit
28c17613c4
@ -19,10 +19,12 @@ from ldm.util import debug_image
|
|||||||
|
|
||||||
|
|
||||||
def infill_methods()->list[str]:
|
def infill_methods()->list[str]:
|
||||||
methods = list()
|
methods = [
|
||||||
|
"tile",
|
||||||
|
"solid",
|
||||||
|
]
|
||||||
if PatchMatch.patchmatch_available():
|
if PatchMatch.patchmatch_available():
|
||||||
methods.append('patchmatch')
|
methods.insert(0, 'patchmatch')
|
||||||
methods.append('tile')
|
|
||||||
return methods
|
return methods
|
||||||
|
|
||||||
class Inpaint(Img2Img):
|
class Inpaint(Img2Img):
|
||||||
@ -182,6 +184,7 @@ class Inpaint(Img2Img):
|
|||||||
infill_method = None,
|
infill_method = None,
|
||||||
inpaint_width=None,
|
inpaint_width=None,
|
||||||
inpaint_height=None,
|
inpaint_height=None,
|
||||||
|
inpaint_fill:tuple(int)=(0x7F, 0x7F, 0x7F, 0xFF),
|
||||||
attention_maps_callback=None,
|
attention_maps_callback=None,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
"""
|
"""
|
||||||
@ -202,12 +205,17 @@ class Inpaint(Img2Img):
|
|||||||
# Do infill
|
# Do infill
|
||||||
if infill_method == 'patchmatch' and PatchMatch.patchmatch_available():
|
if infill_method == 'patchmatch' and PatchMatch.patchmatch_available():
|
||||||
init_filled = self.infill_patchmatch(self.pil_image.copy())
|
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(
|
init_filled = self.tile_fill_missing(
|
||||||
self.pil_image.copy(),
|
self.pil_image.copy(),
|
||||||
seed = self.seed,
|
seed = self.seed,
|
||||||
tile_size = tile_size
|
tile_size = tile_size
|
||||||
)
|
)
|
||||||
|
elif infill_method == 'solid':
|
||||||
|
solid_bg = PIL.Image.new("RGBA", init_image.size, inpaint_fill)
|
||||||
|
init_filled = PIL.Image.alpha_composite(solid_bg, init_image)
|
||||||
|
else:
|
||||||
|
raise ValueError(f"Non-supported infill type {infill_method}", infill_method)
|
||||||
init_filled.paste(init_image, (0,0), init_image.split()[-1])
|
init_filled.paste(init_image, (0,0), init_image.split()[-1])
|
||||||
|
|
||||||
# Resize if requested for inpainting
|
# Resize if requested for inpainting
|
||||||
|
Loading…
x
Reference in New Issue
Block a user