Skip to content

Commit

Permalink
Merge pull request #12470 from Splendide-Imaginarius/mask-blur-proper…
Browse files Browse the repository at this point in the history
…ty+kernel

Make `StableDiffusionProcessingImg2Img.mask_blur` a property, make more inline with PIL `GaussianBlur`
  • Loading branch information
AUTOMATIC1111 authored Aug 11, 2023
2 parents 77c52ea + 5688864 commit ae6b309
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions modules/processing.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -1243,11 +1243,10 @@ def __init__(self, init_images: list = None, resize_mode: int = 0, denoising_str
self.image_mask = mask
self.latent_mask = None
self.mask_for_overlay = None
if mask_blur is not None:
mask_blur_x = mask_blur
mask_blur_y = mask_blur
self.mask_blur_x = mask_blur_x
self.mask_blur_y = mask_blur_y
if mask_blur is not None:
self.mask_blur = mask_blur
self.inpainting_fill = inpainting_fill
self.inpaint_full_res = inpaint_full_res
self.inpaint_full_res_padding = inpaint_full_res_padding
Expand All @@ -1257,6 +1256,22 @@ def __init__(self, init_images: list = None, resize_mode: int = 0, denoising_str
self.nmask = None
self.image_conditioning = None

@property
def mask_blur(self):
if self.mask_blur_x == self.mask_blur_y:
return self.mask_blur_x
return None

@mask_blur.setter
def mask_blur(self, value):
self.mask_blur_x = value
self.mask_blur_y = value

@mask_blur.deleter
def mask_blur(self):
del self.mask_blur_x
del self.mask_blur_y

def init(self, all_prompts, all_seeds, all_subseeds):
self.sampler = sd_samplers.create_sampler(self.sampler_name, self.sd_model)
crop_region = None
Expand All @@ -1271,13 +1286,13 @@ def init(self, all_prompts, all_seeds, all_subseeds):

if self.mask_blur_x > 0:
np_mask = np.array(image_mask)
kernel_size = 2 * int(4 * self.mask_blur_x + 0.5) + 1
kernel_size = 2 * int(2.5 * self.mask_blur_x + 0.5) + 1
np_mask = cv2.GaussianBlur(np_mask, (kernel_size, 1), self.mask_blur_x)
image_mask = Image.fromarray(np_mask)

if self.mask_blur_y > 0:
np_mask = np.array(image_mask)
kernel_size = 2 * int(4 * self.mask_blur_y + 0.5) + 1
kernel_size = 2 * int(2.5 * self.mask_blur_y + 0.5) + 1
np_mask = cv2.GaussianBlur(np_mask, (1, kernel_size), self.mask_blur_y)
image_mask = Image.fromarray(np_mask)

Expand Down

0 comments on commit ae6b309

Please sign in to comment.