Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
71314e47
Commit
71314e47
authored
Apr 18, 2024
by
storyicon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:compatible with inconsistent/empty mask
Signed-off-by:
storyicon
<
storyicon@foxmail.com
>
parent
0980fdfe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
12 deletions
+15
-12
modules/masking.py
modules/masking.py
+2
-2
modules/processing.py
modules/processing.py
+13
-10
No files found.
modules/masking.py
View file @
71314e47
...
...
@@ -9,8 +9,8 @@ def get_crop_region(mask, pad=0):
if
box
:
x1
,
y1
,
x2
,
y2
=
box
else
:
# when no box is found
x1
=
y1
=
0
x2
,
y2
=
mask_img
.
size
x1
,
y1
=
mask_img
.
size
x2
=
y2
=
0
return
max
(
x1
-
pad
,
0
),
max
(
y1
-
pad
,
0
),
min
(
x2
+
pad
,
mask_img
.
size
[
0
]),
min
(
y2
+
pad
,
mask_img
.
size
[
1
])
...
...
modules/processing.py
View file @
71314e47
...
...
@@ -1537,23 +1537,24 @@ class StableDiffusionProcessingImg2Img(StableDiffusionProcessing):
if
self
.
mask_blur_x
>
0
or
self
.
mask_blur_y
>
0
:
self
.
extra_generation_params
[
"Mask blur"
]
=
self
.
mask_blur
if
image_mask
.
size
!=
(
self
.
width
,
self
.
height
):
image_mask
=
images
.
resize_image
(
self
.
resize_mode
,
image_mask
,
self
.
width
,
self
.
height
)
if
self
.
inpaint_full_res
:
self
.
mask_for_overlay
=
image_mask
mask
=
image_mask
.
convert
(
'L'
)
crop_region
=
masking
.
get_crop_region
(
mask
,
self
.
inpaint_full_res_padding
)
crop_region
=
masking
.
expand_crop_region
(
crop_region
,
self
.
width
,
self
.
height
,
mask
.
width
,
mask
.
height
)
x1
,
y1
,
x2
,
y2
=
crop_region
mask
=
mask
.
crop
(
crop_region
)
image_mask
=
images
.
resize_image
(
2
,
mask
,
self
.
width
,
self
.
height
)
self
.
paste_to
=
(
x1
,
y1
,
x2
-
x1
,
y2
-
y1
)
if
crop_region
[
0
]
>=
crop_region
[
2
]
and
crop_region
[
1
]
>=
crop_region
[
3
]:
crop_region
=
None
image_mask
=
None
self
.
mask_for_overlay
=
None
else
:
crop_region
=
masking
.
expand_crop_region
(
crop_region
,
self
.
width
,
self
.
height
,
mask
.
width
,
mask
.
height
)
x1
,
y1
,
x2
,
y2
=
crop_region
mask
=
mask
.
crop
(
crop_region
)
image_mask
=
images
.
resize_image
(
2
,
mask
,
self
.
width
,
self
.
height
)
self
.
paste_to
=
(
x1
,
y1
,
x2
-
x1
,
y2
-
y1
)
self
.
extra_generation_params
[
"Inpaint area"
]
=
"Only masked"
self
.
extra_generation_params
[
"Masked area padding"
]
=
self
.
inpaint_full_res_padding
else
:
image_mask
=
images
.
resize_image
(
self
.
resize_mode
,
image_mask
,
self
.
width
,
self
.
height
)
np_mask
=
np
.
array
(
image_mask
)
np_mask
=
np
.
clip
((
np_mask
.
astype
(
np
.
float32
))
*
2
,
0
,
255
)
.
astype
(
np
.
uint8
)
self
.
mask_for_overlay
=
Image
.
fromarray
(
np_mask
)
...
...
@@ -1579,6 +1580,8 @@ class StableDiffusionProcessingImg2Img(StableDiffusionProcessing):
image
=
images
.
resize_image
(
self
.
resize_mode
,
image
,
self
.
width
,
self
.
height
)
if
image_mask
is
not
None
:
if
self
.
mask_for_overlay
.
size
!=
(
image
.
width
,
image
.
height
):
self
.
mask_for_overlay
=
images
.
resize_image
(
self
.
resize_mode
,
self
.
mask_for_overlay
,
image
.
width
,
image
.
height
)
image_masked
=
Image
.
new
(
'RGBa'
,
(
image
.
width
,
image
.
height
))
image_masked
.
paste
(
image
.
convert
(
"RGBA"
)
.
convert
(
"RGBa"
),
mask
=
ImageOps
.
invert
(
self
.
mask_for_overlay
.
convert
(
'L'
)))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment