Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make StableDiffusionProcessingImg2Img.mask_blur a property, make more inline with PIL GaussianBlur #12470

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions modules/processing.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -1232,11 +1232,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 @@ -1246,6 +1245,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 @@ -1260,13 +1275,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