aboutsummaryrefslogtreecommitdiff
path: root/modules/img2img.py
diff options
context:
space:
mode:
authorfuzzytent <fuzzy.tent6960@fastmail.com>2022-09-07 22:37:54 +0200
committerfuzzytent <fuzzy.tent6960@fastmail.com>2022-09-07 22:37:54 +0200
commit7045c846435cf5c9547729c60e85c386e78c90ed (patch)
treed0f53a53cc1b9572e10d7accb6a94a52985d4451 /modules/img2img.py
parent296d012423f8d1862a63680443bb88b7d904ba4e (diff)
Also use alpha channel from img2img input image as mask
Diffstat (limited to 'modules/img2img.py')
-rw-r--r--modules/img2img.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/modules/img2img.py b/modules/img2img.py
index 3129798d..1e734ac8 100644
--- a/modules/img2img.py
+++ b/modules/img2img.py
@@ -1,5 +1,5 @@
import math
-from PIL import Image
+from PIL import Image, ImageOps, ImageChops
from modules.processing import Processed, StableDiffusionProcessingImg2Img, process_images
from modules.shared import opts, state
@@ -16,7 +16,9 @@ def img2img(prompt: str, init_img, init_img_with_mask, steps: int, sampler_index
if is_inpaint:
image = init_img_with_mask['image']
- mask = init_img_with_mask['mask']
+ alpha_mask = ImageOps.invert(image.split()[-1]).convert('L').point(lambda x: 255 if x > 0 else 0, mode='1')
+ mask = ImageChops.lighter(alpha_mask, init_img_with_mask['mask'].convert('L')).convert('RGBA')
+ image = image.convert('RGB')
else:
image = init_img
mask = None