Update pictureDeal2.py
Browse files- pictureDeal2.py +22 -23
pictureDeal2.py
CHANGED
|
@@ -5,22 +5,21 @@ import numpy as np
|
|
| 5 |
|
| 6 |
with gr.Blocks() as interface:
|
| 7 |
|
| 8 |
-
with gr.
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
with gr.Accordion("每次调整参数后,点击【加工图片】按钮,得到图片的勾边"):
|
| 15 |
-
with gr.Row():
|
| 16 |
-
enhance = gr.Slider(0, 1, 0.8, step=0.1, label="图片彩色度")
|
| 17 |
-
# blend = gr.Slider(0, 1, 0.4, step=0.1, label="颜色填充度")
|
| 18 |
color = gr.ColorPicker(label="勾边颜色")
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
with gr.Accordion("
|
| 24 |
with gr.Row():
|
| 25 |
closed_output0 = gr.Image(label='简单勾边')
|
| 26 |
closed_output1 = gr.Image(label='常规勾边')
|
|
@@ -39,7 +38,7 @@ with gr.Blocks() as interface:
|
|
| 39 |
|
| 40 |
|
| 41 |
# 调整模型结果参数
|
| 42 |
-
def turn_arguments(img,
|
| 43 |
# def turn_arguments(img,enhance,blend,color):
|
| 44 |
imageX = Image.fromarray(img)
|
| 45 |
contrast = ImageEnhance.Contrast(imageX)
|
|
@@ -79,7 +78,7 @@ with gr.Blocks() as interface:
|
|
| 79 |
image0 = Image.fromarray(img)
|
| 80 |
enhancer0 = ImageEnhance.Color(image=image0)
|
| 81 |
# 增强颜色
|
| 82 |
-
img0 = enhancer0.enhance(enhance).convert('RGB')
|
| 83 |
# union_img0 = np.asarray(Image.blend(close00, img0, blend))
|
| 84 |
|
| 85 |
|
|
@@ -113,8 +112,8 @@ with gr.Blocks() as interface:
|
|
| 113 |
image1 = Image.fromarray(img)
|
| 114 |
enhancer1 = ImageEnhance.Color(image=image1)
|
| 115 |
# 增强颜色
|
| 116 |
-
img1 = enhancer1.enhance(enhance).convert('RGB')
|
| 117 |
-
union_img1 = np.asarray(Image.blend(close01, img1, blend))
|
| 118 |
|
| 119 |
#####################################
|
| 120 |
# 复杂勾边-自选颜色 #
|
|
@@ -146,7 +145,7 @@ with gr.Blocks() as interface:
|
|
| 146 |
image2 = Image.fromarray(img)
|
| 147 |
enhancer2 = ImageEnhance.Color(image=image2)
|
| 148 |
# 增强颜色
|
| 149 |
-
img2 = enhancer2.enhance(enhance).convert('RGB')
|
| 150 |
# union_img2 = np.asarray(Image.blend(close02, img2, blend))
|
| 151 |
|
| 152 |
#####################################
|
|
@@ -157,18 +156,18 @@ with gr.Blocks() as interface:
|
|
| 157 |
result3[closed3==0] = (255,255,255)
|
| 158 |
close03 = Image.fromarray(result3).convert('RGB')
|
| 159 |
|
| 160 |
-
# 颜色空间转换
|
| 161 |
image3 = Image.fromarray(img)
|
| 162 |
enhancer3 = ImageEnhance.Color(image=image3)
|
| 163 |
# 增强颜色
|
| 164 |
-
img3 = enhancer3.enhance(enhance).convert('RGB')
|
| 165 |
# union_img3 = np.asarray(Image.blend(close03, img3, blend))
|
| 166 |
|
| 167 |
# return result0,union_img0,result1,union_img1,result2,union_img2,result3,union_img3
|
| 168 |
-
return result0,result1,result2,result3
|
| 169 |
|
| 170 |
-
section_btn.click(turn_arguments,inputs=[img_input,
|
| 171 |
-
outputs = [closed_output0,closed_output1,closed_output2,closed_output3
|
| 172 |
# outputs = [closed_output0,img_param_output0,closed_output1,img_param_output1,closed_output2,img_param_output2,closed_output3,img_param_output3])
|
| 173 |
|
| 174 |
interface.launch(show_api=False)
|
|
|
|
| 5 |
|
| 6 |
with gr.Blocks() as interface:
|
| 7 |
|
| 8 |
+
with gr.Row():
|
| 9 |
+
with gr.Accordion("1.请选择一张待加工图片"):
|
| 10 |
+
img_input = gr.Image(label='图片',interactive=True)
|
| 11 |
+
with gr.Accordion("2.可更换勾边颜色,点加工图片"):
|
| 12 |
+
gr.Markdown("网页版效果更好:https://idalee-draweasy.hf.space")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
color = gr.ColorPicker(label="勾边颜色")
|
| 14 |
+
section_btn = gr.Button("加工图片")
|
| 15 |
+
# img_param_output1 = gr.Image(label='勾边合成结果',interactive=False,tool='canvas')
|
| 16 |
|
| 17 |
+
# with gr.Accordion("每次调整参数后,点击【加工图片】按钮,得到图片的勾边"):
|
| 18 |
+
# with gr.Row():
|
| 19 |
+
# enhance = gr.Slider(0, 1, 0.8, step=0.1, label="图片彩色度")
|
| 20 |
+
# blend = gr.Slider(0, 1, 0.4, step=0.1, label="颜色填充度")
|
| 21 |
|
| 22 |
+
with gr.Accordion("【结果】4种勾边效果"):
|
| 23 |
with gr.Row():
|
| 24 |
closed_output0 = gr.Image(label='简单勾边')
|
| 25 |
closed_output1 = gr.Image(label='常规勾边')
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
# 调整模型结果参数
|
| 41 |
+
def turn_arguments(img,color):
|
| 42 |
# def turn_arguments(img,enhance,blend,color):
|
| 43 |
imageX = Image.fromarray(img)
|
| 44 |
contrast = ImageEnhance.Contrast(imageX)
|
|
|
|
| 78 |
image0 = Image.fromarray(img)
|
| 79 |
enhancer0 = ImageEnhance.Color(image=image0)
|
| 80 |
# 增强颜色
|
| 81 |
+
# img0 = enhancer0.enhance(enhance).convert('RGB')
|
| 82 |
# union_img0 = np.asarray(Image.blend(close00, img0, blend))
|
| 83 |
|
| 84 |
|
|
|
|
| 112 |
image1 = Image.fromarray(img)
|
| 113 |
enhancer1 = ImageEnhance.Color(image=image1)
|
| 114 |
# 增强颜色
|
| 115 |
+
# img1 = enhancer1.enhance(enhance).convert('RGB')
|
| 116 |
+
# union_img1 = np.asarray(Image.blend(close01, img1, blend))
|
| 117 |
|
| 118 |
#####################################
|
| 119 |
# 复杂勾边-自选颜色 #
|
|
|
|
| 145 |
image2 = Image.fromarray(img)
|
| 146 |
enhancer2 = ImageEnhance.Color(image=image2)
|
| 147 |
# 增强颜色
|
| 148 |
+
# img2 = enhancer2.enhance(enhance).convert('RGB')
|
| 149 |
# union_img2 = np.asarray(Image.blend(close02, img2, blend))
|
| 150 |
|
| 151 |
#####################################
|
|
|
|
| 156 |
result3[closed3==0] = (255,255,255)
|
| 157 |
close03 = Image.fromarray(result3).convert('RGB')
|
| 158 |
|
| 159 |
+
# 颜色空间转换
|
| 160 |
image3 = Image.fromarray(img)
|
| 161 |
enhancer3 = ImageEnhance.Color(image=image3)
|
| 162 |
# 增强颜色
|
| 163 |
+
# img3 = enhancer3.enhance(enhance).convert('RGB')
|
| 164 |
# union_img3 = np.asarray(Image.blend(close03, img3, blend))
|
| 165 |
|
| 166 |
# return result0,union_img0,result1,union_img1,result2,union_img2,result3,union_img3
|
| 167 |
+
return result0,result1,result2,result3
|
| 168 |
|
| 169 |
+
section_btn.click(turn_arguments,inputs=[img_input,color],
|
| 170 |
+
outputs = [closed_output0,closed_output1,closed_output2,closed_output3])
|
| 171 |
# outputs = [closed_output0,img_param_output0,closed_output1,img_param_output1,closed_output2,img_param_output2,closed_output3,img_param_output3])
|
| 172 |
|
| 173 |
interface.launch(show_api=False)
|