mirror of
https://github.com/Coyote-A/ultimate-upscale-for-automatic1111.git
synced 2026-04-26 09:18:52 +00:00
Better UI
This commit is contained in:
@@ -82,12 +82,10 @@ def redraw_image(p, upscaled_img, rows, cols, tileSize, padding):
|
||||
return upscaled_img, initial_info
|
||||
|
||||
|
||||
def redraw_middle_offset_image(p, upscaled_img, rows, cols, tileSize, padding, offset_pass_denoise, offset_pass_mask_blur):
|
||||
def redraw_middle_offset_image(p, upscaled_img, rows, cols, tileSize, padding, seams_fix_denoise, seams_fix_mask_blur):
|
||||
initial_info = None
|
||||
gradient = Image.linear_gradient("L")
|
||||
|
||||
# gradient = gradient.resize((tileSize, tileSize//2), resample=Image.LANCZOS)
|
||||
|
||||
row_gradient = Image.new("L", (tileSize, tileSize), "black")
|
||||
row_gradient.paste(gradient.resize((tileSize, tileSize//2), resample=Image.BICUBIC), (0, 0))
|
||||
row_gradient.paste(gradient.rotate(180).resize((tileSize, tileSize//2), resample=Image.BICUBIC), (0, tileSize//2))
|
||||
@@ -95,8 +93,8 @@ def redraw_middle_offset_image(p, upscaled_img, rows, cols, tileSize, padding, o
|
||||
col_gradient.paste(gradient.rotate(90).resize((tileSize//2, tileSize), resample=Image.BICUBIC), (0, 0))
|
||||
col_gradient.paste(gradient.rotate(270).resize((tileSize//2, tileSize), resample=Image.BICUBIC), (tileSize//2, 0))
|
||||
|
||||
p.denoising_strength = offset_pass_denoise
|
||||
p.mask_blur = offset_pass_mask_blur
|
||||
p.denoising_strength = seams_fix_denoise
|
||||
p.mask_blur = seams_fix_mask_blur
|
||||
|
||||
for yi in range(rows-1):
|
||||
for xi in range(cols):
|
||||
@@ -133,8 +131,8 @@ def redraw_middle_offset_image(p, upscaled_img, rows, cols, tileSize, padding, o
|
||||
return upscaled_img, initial_info
|
||||
|
||||
|
||||
def seam_draw(p, upscaled_img, seam_pass_width, seam_pass_padding, seam_pass_denoise, padding, tileSize, cols, rows, mask_blur):
|
||||
p.denoising_strength = seam_pass_denoise
|
||||
def seam_draw(p, upscaled_img, seams_fix_width, seams_fix_padding, seams_fix_denoise, padding, tileSize, cols, rows, mask_blur):
|
||||
p.denoising_strength = seams_fix_denoise
|
||||
p.mask_blur = 0
|
||||
|
||||
gradient = Image.linear_gradient("L")
|
||||
@@ -142,16 +140,16 @@ def seam_draw(p, upscaled_img, seam_pass_width, seam_pass_padding, seam_pass_den
|
||||
mirror_gradient.paste(gradient.resize((256, 128), resample=Image.BICUBIC), (0, 0))
|
||||
mirror_gradient.paste(gradient.rotate(180).resize((256, 128), resample=Image.BICUBIC), (0, 128))
|
||||
|
||||
row_gradient = mirror_gradient.resize((upscaled_img.width, seam_pass_width), resample=Image.BICUBIC)
|
||||
col_gradient = mirror_gradient.rotate(90).resize((seam_pass_width, upscaled_img.height), resample=Image.BICUBIC)
|
||||
row_gradient = mirror_gradient.resize((upscaled_img.width, seams_fix_width), resample=Image.BICUBIC)
|
||||
col_gradient = mirror_gradient.rotate(90).resize((seams_fix_width, upscaled_img.height), resample=Image.BICUBIC)
|
||||
|
||||
for xi in range(1, cols):
|
||||
p.width = seam_pass_width + seam_pass_padding * 2
|
||||
p.width = seams_fix_width + seams_fix_padding * 2
|
||||
p.height = upscaled_img.height
|
||||
p.inpaint_full_res = True
|
||||
p.inpaint_full_res_padding = seam_pass_padding
|
||||
p.inpaint_full_res_padding = seams_fix_padding
|
||||
mask = Image.new("L", (upscaled_img.width, upscaled_img.height), "black")
|
||||
mask.paste(col_gradient, (xi * tileSize - seam_pass_width // 2, 0))
|
||||
mask.paste(col_gradient, (xi * tileSize - seams_fix_width // 2, 0))
|
||||
|
||||
p.init_images = [upscaled_img]
|
||||
p.image_mask = mask
|
||||
@@ -160,11 +158,11 @@ def seam_draw(p, upscaled_img, seam_pass_width, seam_pass_padding, seam_pass_den
|
||||
upscaled_img = processed.images[0]
|
||||
for yi in range(1, rows):
|
||||
p.width = upscaled_img.width
|
||||
p.height = seam_pass_width + seam_pass_padding * 2
|
||||
p.height = seams_fix_width + seams_fix_padding * 2
|
||||
p.inpaint_full_res = True
|
||||
p.inpaint_full_res_padding = seam_pass_padding
|
||||
p.inpaint_full_res_padding = seams_fix_padding
|
||||
mask = Image.new("L", (upscaled_img.width, upscaled_img.height), "black")
|
||||
mask.paste(row_gradient, (0, yi * tileSize - seam_pass_width // 2))
|
||||
mask.paste(row_gradient, (0, yi * tileSize - seams_fix_width // 2))
|
||||
|
||||
p.init_images = [upscaled_img]
|
||||
p.image_mask = mask
|
||||
@@ -182,6 +180,13 @@ class Script(scripts.Script):
|
||||
return is_img2img
|
||||
|
||||
def ui(self, is_img2img):
|
||||
|
||||
seams_fix_types = [
|
||||
"None",
|
||||
"Band pass",
|
||||
"Half tile offset pass"
|
||||
]
|
||||
|
||||
info = gr.HTML(
|
||||
"<p style=\"margin-bottom:0.75em\">Will upscale the image to selected with and height</p>")
|
||||
gr.HTML("<p style=\"margin-bottom:0.75em\">Redraw options:</p>")
|
||||
@@ -192,31 +197,25 @@ class Script(scripts.Script):
|
||||
padding = gr.Slider(label='Padding', minimum=0, maximum=128, step=1, value=32)
|
||||
upscaler_index = gr.Radio(label='Upscaler', choices=[x.name for x in shared.sd_upscalers],
|
||||
value=shared.sd_upscalers[0].name, type="index")
|
||||
gr.HTML("<p style=\"margin-bottom:0.75em\">Seams fix (half tile offset pass):</p>")
|
||||
gr.HTML("<p style=\"margin-bottom:0.75em\">Seams fix:</p>")
|
||||
with gr.Row():
|
||||
offset_pass_enabled = gr.Checkbox(label="Enabled")
|
||||
offset_pass_denoise = gr.Slider(label='Denoise', minimum=0, maximum=1, step=0.01, value=0.35)
|
||||
offset_pass_mask_blur = gr.Slider(label='Mask blur', minimum=0, maximum=64, step=1, value=4)
|
||||
offset_pass_padding = gr.Slider(label='Padding', minimum=0, maximum=128, step=1, value=16)
|
||||
gr.HTML("<p style=\"margin-bottom:0.75em\">Seams fix (bands pass):</p>")
|
||||
with gr.Row():
|
||||
seam_pass_enabled = gr.Checkbox(label="Enabled")
|
||||
seam_pass_width = gr.Slider(label='Width', minimum=0, maximum=128, step=1, value=64)
|
||||
seam_pass_denoise = gr.Slider(label='Denoise', minimum=0, maximum=1, step=0.01, value=0.35)
|
||||
seam_pass_padding = gr.Slider(label='Padding', minimum=0, maximum=128, step=1, value=64)
|
||||
seams_fix_type = gr.Dropdown(label="Type", choices=[k for k in seams_fix_types], type="index", value=next(iter(seams_fix_types)))
|
||||
seams_fix_denoise = gr.Slider(label='Denoise', minimum=0, maximum=1, step=0.01, value=0.35)
|
||||
seams_fix_width = gr.Slider(label='Width', minimum=0, maximum=128, step=1, value=64)
|
||||
seams_fix_mask_blur = gr.Slider(label='Mask blur', minimum=0, maximum=64, step=1, value=4)
|
||||
seams_fix_padding = gr.Slider(label='Padding', minimum=0, maximum=128, step=1, value=16)
|
||||
gr.HTML("<p style=\"margin-bottom:0.75em\">Save options:</p>")
|
||||
with gr.Row():
|
||||
save_upscaled_image = gr.Checkbox(label="Upscaled", value=True)
|
||||
save_offset_path_image = gr.Checkbox(label="Offset pass", value=False)
|
||||
save_seam_path_image = gr.Checkbox(label="Bands path", value=False)
|
||||
save_seams_fix_image = gr.Checkbox(label="Seams fix", value=False)
|
||||
|
||||
return [info, tileSize, mask_blur, padding, seam_pass_enabled, seam_pass_width, seam_pass_denoise,
|
||||
seam_pass_padding, upscaler_index, save_upscaled_image, save_seam_path_image, redraw_enabled,
|
||||
offset_pass_enabled, offset_pass_denoise, offset_pass_padding, save_offset_path_image, offset_pass_mask_blur]
|
||||
return [info, tileSize, mask_blur, padding, seams_fix_width, seams_fix_denoise, seams_fix_padding,
|
||||
upscaler_index, save_upscaled_image, redraw_enabled, save_seams_fix_image, seams_fix_mask_blur,
|
||||
seams_fix_type]
|
||||
|
||||
def run(self, p, _, tileSize, mask_blur, padding, seam_pass_enabled, seam_pass_width, seam_pass_denoise,
|
||||
seam_pass_padding, upscaler_index, save_upscaled_image, save_seam_path_image, redraw_enabled,
|
||||
offset_pass_enabled, offset_pass_denoise, offset_pass_padding, save_offset_path_image, offset_pass_mask_blur):
|
||||
def run(self, p, _, tileSize, mask_blur, padding, seams_fix_width, seams_fix_denoise, seams_fix_padding,
|
||||
upscaler_index, save_upscaled_image, redraw_enabled, save_seams_fix_image, seams_fix_mask_blur,
|
||||
seams_fix_type):
|
||||
processing.fix_seed(p)
|
||||
p.extra_generation_params["SD upscale tileSize"] = tileSize
|
||||
p.mask_blur = mask_blur
|
||||
@@ -243,13 +242,13 @@ class Script(scripts.Script):
|
||||
|
||||
print(f"Tiles amount: {rows * cols}")
|
||||
print(f"Grid: {rows}x{cols}")
|
||||
print(f"Seam path: {seam_pass_enabled}")
|
||||
print(f"Seam path: {seams_fix_type}")
|
||||
|
||||
seams = 0
|
||||
if seam_pass_enabled:
|
||||
if seams_fix_type > 0:
|
||||
seams = rows - 1 + cols - 1
|
||||
state.job_count = ((rows * cols) if redraw_enabled else 0) + (seams if seam_pass_enabled else 0) + (
|
||||
(rows * (cols - 1) + (rows - 1) * cols) if offset_pass_enabled else 0)
|
||||
state.job_count = ((rows * cols) if redraw_enabled else 0) + (seams if seams_fix_type == 1 else 0) + (
|
||||
(rows * (cols - 1) + (rows - 1) * cols) if seams_fix_type == 2 else 0)
|
||||
|
||||
result_images = []
|
||||
result_image = upscaled_img
|
||||
@@ -259,18 +258,18 @@ class Script(scripts.Script):
|
||||
if save_upscaled_image:
|
||||
images.save_image(result_image, p.outpath_samples, "", seed, p.prompt, opts.grid_format, info=initial_info, p=p)
|
||||
|
||||
if offset_pass_enabled:
|
||||
if seams_fix_type == 2:
|
||||
print(f"Starting offset pass drawing")
|
||||
result_image, initial_info = redraw_middle_offset_image(p, result_image, rows, cols, tileSize, offset_pass_padding, offset_pass_denoise, offset_pass_mask_blur)
|
||||
result_image, initial_info = redraw_middle_offset_image(p, result_image, rows, cols, tileSize, seams_fix_padding, seams_fix_denoise, seams_fix_mask_blur)
|
||||
result_images.append(result_image)
|
||||
if save_offset_path_image:
|
||||
if save_seams_fix_image:
|
||||
images.save_image(result_image, p.outpath_samples, "", seed, p.prompt, opts.grid_format, info=initial_info, p=p)
|
||||
|
||||
if seam_pass_enabled:
|
||||
if seams_fix_type == 1:
|
||||
print(f"Starting bands pass drawing")
|
||||
result_image = seam_draw(p, result_image, seam_pass_width, seam_pass_padding, seam_pass_denoise, padding, tileSize, cols, rows, 0)
|
||||
result_image = seam_draw(p, result_image, seams_fix_width, seams_fix_padding, seams_fix_denoise, padding, tileSize, cols, rows, 0)
|
||||
result_images.append(result_image)
|
||||
if save_seam_path_image:
|
||||
if save_seams_fix_image:
|
||||
images.save_image(result_image, p.outpath_samples, "", seed, p.prompt, opts.grid_format, info=initial_info, p=p)
|
||||
|
||||
processed = Processed(p, result_images, seed, initial_info if initial_info is not None else "")
|
||||
|
||||
Reference in New Issue
Block a user