Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Overbill1683
Stable Diffusion Webui
提交
59bb1d36
S
Stable Diffusion Webui
项目概览
Overbill1683
/
Stable Diffusion Webui
10 个月 前同步成功
通知
1736
Star
81
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
S
Stable Diffusion Webui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
59bb1d36
编写于
11月 08, 2022
作者:
K
kavorite
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
blur mask with color-sketch + add paint transparency slider
上级
c34542a4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
16 addition
and
8 deletion
+16
-8
modules/img2img.py
modules/img2img.py
+13
-8
modules/ui.py
modules/ui.py
+3
-0
未找到文件。
modules/img2img.py
浏览文件 @
59bb1d36
...
...
@@ -4,7 +4,7 @@ import sys
import
traceback
import
numpy
as
np
from
PIL
import
Image
,
ImageOps
,
Image
Chops
from
PIL
import
Image
,
ImageOps
,
Image
Filter
,
ImageEnhance
from
modules
import
devices
from
modules.processing
import
Processed
,
StableDiffusionProcessingImg2Img
,
process_images
...
...
@@ -40,7 +40,7 @@ def process_batch(p, input_dir, output_dir, args):
img
=
Image
.
open
(
image
)
# Use the EXIF orientation of photos taken by smartphones.
img
=
ImageOps
.
exif_transpose
(
img
)
img
=
ImageOps
.
exif_transpose
(
img
)
p
.
init_images
=
[
img
]
*
p
.
batch_size
proc
=
modules
.
scripts
.
scripts_img2img
.
run
(
p
,
*
args
)
...
...
@@ -59,7 +59,7 @@ def process_batch(p, input_dir, output_dir, args):
processed_image
.
save
(
os
.
path
.
join
(
output_dir
,
filename
))
def
img2img
(
mode
:
int
,
prompt
:
str
,
negative_prompt
:
str
,
prompt_style
:
str
,
prompt_style2
:
str
,
init_img
,
init_img_with_mask
,
init_img_with_mask_orig
,
init_img_inpaint
,
init_mask_inpaint
,
mask_mode
,
steps
:
int
,
sampler_index
:
int
,
mask_blur
:
int
,
inpainting_fill
:
int
,
restore_faces
:
bool
,
tiling
:
bool
,
n_iter
:
int
,
batch_size
:
int
,
cfg_scale
:
float
,
denoising_strength
:
float
,
seed
:
int
,
subseed
:
int
,
subseed_strength
:
float
,
seed_resize_from_h
:
int
,
seed_resize_from_w
:
int
,
seed_enable_extras
:
bool
,
height
:
int
,
width
:
int
,
resize_mode
:
int
,
inpaint_full_res
:
bool
,
inpaint_full_res_padding
:
int
,
inpainting_mask_invert
:
int
,
img2img_batch_input_dir
:
str
,
img2img_batch_output_dir
:
str
,
*
args
):
def
img2img
(
mode
:
int
,
prompt
:
str
,
negative_prompt
:
str
,
prompt_style
:
str
,
prompt_style2
:
str
,
init_img
,
init_img_with_mask
,
init_img_with_mask_orig
,
init_img_inpaint
,
init_mask_inpaint
,
mask_mode
,
steps
:
int
,
sampler_index
:
int
,
mask_blur
:
int
,
mask_alpha
:
float
,
inpainting_fill
:
int
,
restore_faces
:
bool
,
tiling
:
bool
,
n_iter
:
int
,
batch_size
:
int
,
cfg_scale
:
float
,
denoising_strength
:
float
,
seed
:
int
,
subseed
:
int
,
subseed_strength
:
float
,
seed_resize_from_h
:
int
,
seed_resize_from_w
:
int
,
seed_enable_extras
:
bool
,
height
:
int
,
width
:
int
,
resize_mode
:
int
,
inpaint_full_res
:
bool
,
inpaint_full_res_padding
:
int
,
inpainting_mask_invert
:
int
,
img2img_batch_input_dir
:
str
,
img2img_batch_output_dir
:
str
,
*
args
):
is_inpaint
=
mode
==
1
is_batch
=
mode
==
2
...
...
@@ -68,15 +68,20 @@ def img2img(mode: int, prompt: str, negative_prompt: str, prompt_style: str, pro
if
mask_mode
==
0
:
image
=
init_img_with_mask
is_mask_sketch
=
isinstance
(
image
,
dict
)
if
is_mask_sketch
:
is_mask_paint
=
not
is_mask_sketch
if
is_mask_sketch
:
# Sketch: mask iff. not transparent
image
,
mask
=
image
[
"image"
],
image
[
"mask"
]
mask
=
np
.
array
(
mask
)[...,
-
1
]
>
0
pred
=
np
.
array
(
mask
)[...,
-
1
]
>
0
else
:
# Color-sketch: mask iff. painted over
orig
=
init_img_with_mask_orig
or
image
mask
=
np
.
any
(
np
.
array
(
image
)
!=
np
.
array
(
orig
),
axis
=-
1
)
mask
=
Image
.
fromarray
(
mask
.
astype
(
np
.
uint8
)
*
255
,
"L"
)
pred
=
np
.
any
(
np
.
array
(
image
)
!=
np
.
array
(
orig
),
axis
=-
1
)
mask
=
Image
.
fromarray
(
pred
.
astype
(
np
.
uint8
)
*
255
,
"L"
)
if
is_mask_paint
:
mask
=
ImageEnhance
.
Brightness
(
mask
).
enhance
(
1
-
mask_alpha
/
100
)
blur
=
ImageFilter
.
GaussianBlur
(
mask_blur
)
image
=
Image
.
composite
(
image
.
filter
(
blur
),
orig
,
mask
.
filter
(
blur
))
image
=
image
.
convert
(
"RGB"
)
# Uploaded mask
else
:
...
...
@@ -89,7 +94,7 @@ def img2img(mode: int, prompt: str, negative_prompt: str, prompt_style: str, pro
# Use the EXIF orientation of photos taken by smartphones.
if
image
is
not
None
:
image
=
ImageOps
.
exif_transpose
(
image
)
image
=
ImageOps
.
exif_transpose
(
image
)
assert
0.
<=
denoising_strength
<=
1.
,
'can only work with strength in [0.0, 1.0]'
...
...
modules/ui.py
浏览文件 @
59bb1d36
...
...
@@ -854,6 +854,8 @@ def create_ui(wrap_gradio_gpu_call):
init_img_inpaint
=
gr
.
Image
(
label
=
"Image for img2img"
,
show_label
=
False
,
source
=
"upload"
,
interactive
=
True
,
type
=
"pil"
,
visible
=
False
,
elem_id
=
"img_inpaint_base"
)
init_mask_inpaint
=
gr
.
Image
(
label
=
"Mask"
,
source
=
"upload"
,
interactive
=
True
,
type
=
"pil"
,
visible
=
False
,
elem_id
=
"img_inpaint_mask"
)
show_mask_alpha
=
cmd_opts
.
gradio_inpaint_tool
==
"color-sketch"
mask_alpha
=
gr
.
Slider
(
label
=
"Mask transparency"
,
interactive
=
show_mask_alpha
,
visible
=
show_mask_alpha
)
mask_blur
=
gr
.
Slider
(
label
=
'Mask blur'
,
minimum
=
0
,
maximum
=
64
,
step
=
1
,
value
=
4
)
with
gr
.
Row
():
...
...
@@ -948,6 +950,7 @@ def create_ui(wrap_gradio_gpu_call):
steps
,
sampler_index
,
mask_blur
,
mask_alpha
,
inpainting_fill
,
restore_faces
,
tiling
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录