1
0
Fork 0

full-res inptaining as parameters

This commit is contained in:
HoopyFreud 2023-07-10 23:16:17 -04:00
parent 58b5d18608
commit 3c1fa6094e
3 changed files with 32 additions and 3 deletions

View File

@ -221,6 +221,8 @@ def run_inpaint_pipeline(
mask_filter: Any,
fill_color: str,
tile_order: str,
full_res_inpaint: bool,
full_res_inpaint_padding: float,
) -> None:
logger.debug("building inpaint pipeline")
tile_size = params.tiles
@ -251,13 +253,15 @@ def run_inpaint_pipeline(
# check if we can do full-res inpainting if no outpainting is done
logger.debug("border zero: %s", border.isZero())
if border.isZero():
if full_res_inpaint and border.isZero():
mask_left, mask_top, mask_right, mask_bottom = mask.getbbox()
logger.debug("mask bbox: %s", mask.getbbox())
mask_width = mask_right - mask_left
mask_height = mask_bottom - mask_top
# ensure we have some padding around the mask when we do the inpaint (and that the region size is even)
adj_mask_size = ceil(max(mask_width, mask_height) * 1.2 / 2) * 2
adj_mask_size = (
ceil(max(mask_width, mask_height) * full_res_inpaint_padding / 2) * 2
)
mask_center_x = int(round((mask_right + mask_left) / 2))
mask_center_y = int(round((mask_bottom + mask_top) / 2))
adj_mask_border = (
@ -293,7 +297,7 @@ def run_inpaint_pipeline(
adj_mask_border,
)
if border_integrity and adj_mask_size <= tile_size:
full_res_inpaint = True
logger.debug("performing full-res inpainting")
original_source = source
source = source.crop(adj_mask_border)
source = ImageOps.contain(source, (tile_size, tile_size))
@ -302,6 +306,9 @@ def run_inpaint_pipeline(
if is_debug():
save_image(server, "adjusted-mask.png", mask)
save_image(server, "adjusted-source.png", source)
else:
logger.debug("cannot perform full-res inpaint due to size issue")
full_res_inpaint = False
# set up the chain pipeline and base stage
chain = ChainPipeline()

View File

@ -23,6 +23,7 @@ from ..utils import (
base_join,
get_and_clamp_float,
get_and_clamp_int,
get_boolean,
get_from_list,
get_from_map,
get_not_empty,
@ -257,6 +258,17 @@ def inpaint(server: ServerContext, pool: DevicePoolExecutor):
mask.alpha_composite(mask_top_layer)
mask.convert(mode="L")
full_res_inpaint = get_boolean(
request.args, "fullresInpaint", get_config_value("fullresInpaint")
)
full_res_inpaint_padding = get_and_clamp_float(
request.args,
"fullresInpaintPadding",
get_config_value("fullresInpaintPadding"),
get_config_value("fullresInpaintPadding", "max"),
get_config_value("fullresInpaintPadding", "min"),
)
device, params, _size = pipeline_from_request(server, "inpaint")
expand = border_from_request()
upscale = upscale_from_request()
@ -306,6 +318,8 @@ def inpaint(server: ServerContext, pool: DevicePoolExecutor):
mask_filter,
fill_color,
tile_order,
full_res_inpaint,
full_res_inpaint_padding,
needs_device=device,
)

View File

@ -58,6 +58,14 @@
"default": "none",
"keys": []
},
"fullresInpaint": {
"default": true
},
"fullresInpaintPadding": {
"default": 1.2,
"min": 1,
"max": 2
},
"height": {
"default": 512,
"min": 256,