From 852d3452b8bf0893f84e85cbb28d40b3a7026ba7 Mon Sep 17 00:00:00 2001 From: Chengsong Zhang Date: Wed, 26 Apr 2023 10:28:25 +0800 Subject: [PATCH] remove sketch logic --- README.md | 7 +++++++ scripts/process_params.py | 26 ++++++++++---------------- scripts/sam.py | 4 ---- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index be62b91..4ddc883 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,13 @@ This extension aim for connecting [AUTOMATIC1111 Stable Diffusion WebUI](https:/ This extension has been significantly refactored on `2023/04/24`. If you wish to revert to older version, please `git checkout 724b4db`. +## TODO + +- [ ] Color selection for mask region and unmask region +- [ ] Batch ControlNet inpainting +- [ ] What does "Masked content" mean? +- [ ] Test EditAnything + ## FAQ Thanks for suggestions from [github issues](https://github.com/continue-revolution/sd-webui-segment-anything/issues), [reddit](https://www.reddit.com/r/StableDiffusion/comments/12hkdy8/sd_webui_segment_everything/) and [bilibili](https://www.bilibili.com/video/BV1Tg4y1u73r/) to make this extension better. diff --git a/scripts/process_params.py b/scripts/process_params.py index f73b396..cae9254 100644 --- a/scripts/process_params.py +++ b/scripts/process_params.py @@ -22,9 +22,6 @@ def __init__(self, args: Tuple, is_img2img=False): self.output_chosen_mask: int = 0 self.dilation_checkbox: bool = False self.dilation_output_gallery: List[Dict] = None - self.sketch_checkbox: bool = False - self.inpaint_color_sketch = None - self.inpaint_mask_alpha: int = 0 self.init_sam_single_image_process(args) @@ -37,9 +34,6 @@ def init_sam_single_image_process(self, args): self.output_chosen_mask = args[5] self.dilation_checkbox = args[6] self.dilation_output_gallery = args[7] - self.sketch_checkbox = args[8] - self.inpaint_color_sketch = args[9] - self.inpaint_mask_alpha = args[10] def get_input_and_mask(self, mask_blur): @@ -51,14 +45,14 @@ def get_input_and_mask(self, mask_blur): mask = Image.open(self.output_mask_gallery[self.output_chosen_mask + 3]['name']).convert('L') if mask is not None and self.cnet_inpaint_invert: mask = ImageOps.invert(mask) - if self.is_img2img and self.sketch_checkbox and self.inpaint_color_sketch is not None and mask is not None: - alpha = np.expand_dims(np.array(mask) / 255, axis=-1) - image = np.uint8(np.array(self.inpaint_color_sketch) * alpha + np.array(self.input_image) * (1 - alpha)) - mask = ImageEnhance.Brightness(mask).enhance(1 - self.inpaint_mask_alpha / 100) - blur = ImageFilter.GaussianBlur(mask_blur) - image = Image.composite(image.filter(blur), self.input_image, mask.filter(blur)).convert("RGB") - else: - image = self.input_image + # if self.is_img2img and self.sketch_checkbox and self.inpaint_color_sketch is not None and mask is not None: + # alpha = np.expand_dims(np.array(mask) / 255, axis=-1) + # image = np.uint8(np.array(self.inpaint_color_sketch) * alpha + np.array(self.input_image) * (1 - alpha)) + # mask = ImageEnhance.Brightness(mask).enhance(1 - self.inpaint_mask_alpha / 100) + # blur = ImageFilter.GaussianBlur(mask_blur) + # image = Image.composite(image.filter(blur), self.input_image, mask.filter(blur)).convert("RGB") + # else: + image = self.input_image return image, mask @@ -66,8 +60,8 @@ def get_input_and_mask(self, mask_blur): class SAMProcessUnit: def __init__(self, args: Tuple, is_img2img=False): self.is_img2img = is_img2img - sam_inpaint_args = args[:11] - args = args[11:] + sam_inpaint_args = args[:8] + args = args[8:] self.sam_inpaint_unit = SAMInpaintUnit(sam_inpaint_args, is_img2img) self.cnet_seg_output_gallery: List[Dict] = None diff --git a/scripts/sam.py b/scripts/sam.py index 7888b1e..eea3e4c 100644 --- a/scripts/sam.py +++ b/scripts/sam.py @@ -608,8 +608,6 @@ def ui(self, is_img2img): sam_inpaint_upload_enable, sam_cnet_inpaint_invert, sam_cnet_inpaint_idx, sam_input_image, sam_output_mask_gallery, sam_output_chosen_mask, sam_dilation_checkbox, sam_dilation_output_gallery) - sam_sketch_checkbox, sam_inpaint_color_sketch, sam_inpaint_mask_alpha = ui_sketch(sam_input_image, is_img2img) - sam_single_image_process += (sam_sketch_checkbox, sam_inpaint_color_sketch, sam_inpaint_mask_alpha) ui_process += sam_single_image_process with gr.TabItem(label="Batch Process"): @@ -722,8 +720,6 @@ def layout_show(mode): crop_inpaint_enable, crop_cnet_inpaint_invert, crop_cnet_inpaint_idx, crop_resized_image, crop_output_gallery, crop_padding, crop_dilation_checkbox, crop_dilation_output_gallery) - crop_sketch_checkbox, crop_inpaint_color_sketch, crop_inpaint_mask_alpha = ui_sketch(crop_resized_image, is_img2img) - crop_single_image_process += (crop_sketch_checkbox, crop_inpaint_color_sketch, crop_inpaint_mask_alpha) ui_process += crop_single_image_process with gr.TabItem(label="Batch Process"):