diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2022-09-08 08:09:28 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-08 08:09:28 +0300 |
commit | 0959fa2d027e7a093adb3cfab9be2343ec7348e2 (patch) | |
tree | a8ab138b26d5b83d25c8bb3b7a928a71eda828e6 /modules/img2img.py | |
parent | 782b819a553404f43b67fe1ca19afd5678af4834 (diff) | |
parent | 7045c846435cf5c9547729c60e85c386e78c90ed (diff) |
Merge pull request #124 from fuzzytent/alpha-mask
Also use alpha channel from img2img input image as mask
Diffstat (limited to 'modules/img2img.py')
-rw-r--r-- | modules/img2img.py | 6 |
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
|