Skip to content

Commit

Permalink
remove sketch logic
Browse files Browse the repository at this point in the history
  • Loading branch information
continue-revolution committed Apr 26, 2023
1 parent dc59b3e commit 852d345
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 10 additions & 16 deletions scripts/process_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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):
Expand All @@ -51,23 +45,23 @@ 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



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
Expand Down
4 changes: 0 additions & 4 deletions scripts/sam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down Expand Up @@ -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"):
Expand Down

0 comments on commit 852d345

Please sign in to comment.