IdaLee commited on
Commit
9617e1f
·
1 Parent(s): 034b2de

Update pictureDeal2.py

Browse files
Files changed (1) hide show
  1. pictureDeal2.py +14 -9
pictureDeal2.py CHANGED
@@ -7,13 +7,16 @@ with gr.Blocks() as interface:
7
 
8
  with gr.Accordion("请选择一张图片"):
9
  # gr.Markdown("Look at me...")
10
- img_input = gr.Image(label='请选择一张待加工图片')
 
 
11
 
12
  with gr.Accordion("每次调整参数后,点击【加工图片】按钮,得到图片的勾边"):
13
  with gr.Row():
14
  enhance = gr.Slider(0, 1, 0.8, step=0.1, label="图片彩色度")
15
- blend = gr.Slider(0, 1, 0.4, step=0.1, label="颜色填充度")
16
  color = gr.ColorPicker(label="勾边颜色")
 
17
 
18
  section_btn = gr.Button("加工图片")
19
 
@@ -36,7 +39,8 @@ with gr.Blocks() as interface:
36
 
37
 
38
  # 调整模型结果参数
39
- def turn_arguments(img,enhance,blend,color):
 
40
  imageX = Image.fromarray(img)
41
  contrast = ImageEnhance.Contrast(imageX)
42
  imageX = contrast.enhance(1.5)
@@ -53,6 +57,7 @@ with gr.Blocks() as interface:
53
  canny_end_0 = 100
54
  thresh_val_0 = 205
55
  maxval_0 = 330
 
56
  gray0 = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
57
  # 对灰度图像进行高斯滤波,以去除噪声
58
  gray0 = cv2.GaussianBlur(gray0, (gaussian_blur_0,gaussian_blur_0), 0)
@@ -75,7 +80,7 @@ with gr.Blocks() as interface:
75
  enhancer0 = ImageEnhance.Color(image=image0)
76
  # 增强颜色
77
  img0 = enhancer0.enhance(enhance).convert('RGB')
78
- union_img0 = np.asarray(Image.blend(close00, img0, blend))
79
 
80
 
81
  #####################################
@@ -142,7 +147,7 @@ with gr.Blocks() as interface:
142
  enhancer2 = ImageEnhance.Color(image=image2)
143
  # 增强颜色
144
  img2 = enhancer2.enhance(enhance).convert('RGB')
145
- union_img2 = np.asarray(Image.blend(close02, img2, blend))
146
 
147
  #####################################
148
  # 简单勾边-彩色勾边 #
@@ -157,13 +162,13 @@ with gr.Blocks() as interface:
157
  enhancer3 = ImageEnhance.Color(image=image3)
158
  # 增强颜色
159
  img3 = enhancer3.enhance(enhance).convert('RGB')
160
- union_img3 = np.asarray(Image.blend(close03, img3, blend))
161
 
162
  # return result0,union_img0,result1,union_img1,result2,union_img2,result3,union_img3
163
- return result0,result1,result2,result3
164
 
165
- section_btn.click(turn_arguments,inputs=[img_input,enhance,blend,color],
166
- outputs = [closed_output0,closed_output1,closed_output2,closed_output3])
167
  # outputs = [closed_output0,img_param_output0,closed_output1,img_param_output1,closed_output2,img_param_output2,closed_output3,img_param_output3])
168
 
169
  interface.launch(show_api=False)
 
7
 
8
  with gr.Accordion("请选择一张图片"):
9
  # gr.Markdown("Look at me...")
10
+ with gr.Row():
11
+ img_input = gr.Image(label='请选择一张待加工图片',interactive=True)
12
+ img_param_output1 = gr.Image(label='勾边合成结果',interactive=False,tool='canvas')
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
  section_btn = gr.Button("加工图片")
22
 
 
39
 
40
 
41
  # 调整模型结果参数
42
+ def turn_arguments(img,enhance,color):
43
+ # def turn_arguments(img,enhance,blend,color):
44
  imageX = Image.fromarray(img)
45
  contrast = ImageEnhance.Contrast(imageX)
46
  imageX = contrast.enhance(1.5)
 
57
  canny_end_0 = 100
58
  thresh_val_0 = 205
59
  maxval_0 = 330
60
+ blend = 0.4
61
  gray0 = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
62
  # 对灰度图像进行高斯滤波,以去除噪声
63
  gray0 = cv2.GaussianBlur(gray0, (gaussian_blur_0,gaussian_blur_0), 0)
 
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
 
86
  #####################################
 
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
  #####################################
153
  # 简单勾边-彩色勾边 #
 
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,union_img1
169
 
170
+ section_btn.click(turn_arguments,inputs=[img_input,enhance,color],
171
+ outputs = [closed_output0,closed_output1,closed_output2,closed_output3,img_param_output1])
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)