diff --git a/extras/preprocessors.py b/extras/preprocessors.py index 05f7c2fd..7720c085 100644 --- a/extras/preprocessors.py +++ b/extras/preprocessors.py @@ -3,25 +3,25 @@ import numpy as np import modules.advanced_parameters as advanced_parameters -def centered_canny(x: np.ndarray, canny_low_threshold): +def centered_canny(x: np.ndarray, canny_low_threshold, canny_high_threshold): assert isinstance(x, np.ndarray) assert x.ndim == 2 and x.dtype == np.uint8 - y = cv2.Canny(x, int(canny_low_threshold), int(advanced_parameters.canny_high_threshold)) + y = cv2.Canny(x, int(canny_low_threshold), int(canny_high_threshold)) y = y.astype(np.float32) / 255.0 return y -def centered_canny_color(x: np.ndarray, canny_low_threshold): +def centered_canny_color(x: np.ndarray, canny_low_threshold, canny_high_threshold): assert isinstance(x, np.ndarray) assert x.ndim == 3 and x.shape[2] == 3 - result = [centered_canny(x[..., i], canny_low_threshold) for i in range(3)] + result = [centered_canny(x[..., i], canny_low_threshold, canny_high_threshold) for i in range(3)] result = np.stack(result, axis=2) return result -def pyramid_canny_color(x: np.ndarray, canny_low_threshold): +def pyramid_canny_color(x: np.ndarray, canny_low_threshold, canny_high_threshold): assert isinstance(x, np.ndarray) assert x.ndim == 3 and x.shape[2] == 3 @@ -31,7 +31,7 @@ def pyramid_canny_color(x: np.ndarray, canny_low_threshold): for k in [0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]: Hs, Ws = int(H * k), int(W * k) small = cv2.resize(x, (Ws, Hs), interpolation=cv2.INTER_AREA) - edge = centered_canny_color(small, canny_low_threshold) + edge = centered_canny_color(small, canny_low_threshold, canny_high_threshold) if acc_edge is None: acc_edge = edge else: @@ -54,11 +54,11 @@ def norm255(x, low=4, high=96): return x * 255.0 -def canny_pyramid(x, canny_low_threshold): +def canny_pyramid(x, canny_low_threshold, canny_high_threshold): # For some reasons, SAI's Control-lora Canny seems to be trained on canny maps with non-standard resolutions. # Then we use pyramid to use all resolutions to avoid missing any structure in specific resolutions. - color_canny = pyramid_canny_color(x, canny_low_threshold) + color_canny = pyramid_canny_color(x, canny_low_threshold, canny_high_threshold) result = np.sum(color_canny, axis=2) return norm255(result, low=1, high=99).clip(0, 255).astype(np.uint8) diff --git a/modules/advanced_parameters.py b/modules/advanced_parameters.py index 3614c9fe..f512afc3 100644 --- a/modules/advanced_parameters.py +++ b/modules/advanced_parameters.py @@ -1,18 +1,18 @@ -controlnet_softness, canny_high_threshold, \ +controlnet_softness, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ - inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 16 + inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate = [None] * 15 def set_all_advanced_parameters(*args): - global controlnet_softness, canny_high_threshold, \ + global controlnet_softness, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate - controlnet_softness, canny_high_threshold, \ + controlnet_softness, \ refiner_swap_method, \ freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2, \ debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field, \ diff --git a/modules/async_worker.py b/modules/async_worker.py index 13b63bf4..192c44e7 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -155,6 +155,7 @@ def worker(): debugging_cn_preprocessor = args.pop() skipping_cn_preprocessor = args.pop() canny_low_threshold = args.pop() + canny_high_threshold = args.pop() cn_tasks = {x: [] for x in flags.ip_list} for _ in range(4): @@ -647,7 +648,7 @@ def worker(): cn_img = resize_image(HWC3(cn_img), width=width, height=height) if not skipping_cn_preprocessor: - cn_img = preprocessors.canny_pyramid(cn_img, canny_low_threshold) + cn_img = preprocessors.canny_pyramid(cn_img, canny_low_threshold, canny_high_threshold) cn_img = HWC3(cn_img) task[0] = core.numpy_to_pytorch(cn_img) diff --git a/webui.py b/webui.py index be0dda86..790b2d41 100644 --- a/webui.py +++ b/webui.py @@ -446,7 +446,7 @@ with shared.gradio_root: freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95) freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2] - adps = [controlnet_softness, canny_high_threshold, refiner_swap_method] + adps = [controlnet_softness, refiner_swap_method] adps += freeu_ctrls adps += inpaint_ctrls @@ -528,7 +528,7 @@ with shared.gradio_root: ctrls += [sampler_name, scheduler_name] ctrls += [overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength] ctrls += [overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint] - ctrls += [debugging_cn_preprocessor, skipping_cn_preprocessor, canny_low_threshold] + ctrls += [debugging_cn_preprocessor, skipping_cn_preprocessor, canny_low_threshold, canny_high_threshold] ctrls += ip_ctrls state_is_generating = gr.State(False)