sunhaha123 commited on
Commit
998c413
1 Parent(s): 32fcd5b
Files changed (1) hide show
  1. main.py +25 -0
main.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import numpy as np
4
+
5
+ def enhance_image(opencv_image, alpha, beta, saturation_factor):
6
+ image = opencv_image
7
+ # 调整亮度和对比度
8
+ image = cv2.convertScaleAbs(image, alpha=alpha, beta=beta)
9
+ # 将图像转换为HSV颜色空间
10
+ hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
11
+ # 调整饱和度
12
+ hsv_image[:, :, 1] = np.clip(hsv_image[:, :, 1] * saturation_factor, 0, 255).astype(np.uint8)
13
+ # 将图像转换回BGR颜色空间
14
+ output_image = cv2.cvtColor(hsv_image, cv2.COLOR_HSV2BGR)
15
+ return output_image
16
+
17
+ iface = gr.Interface(
18
+ fn=enhance_image,
19
+ inputs=["image", gr.inputs.Slider(minimum=0, maximum=2, default=1.02, label="Alpha(对比度增加的比例因子)"),
20
+ gr.inputs.Slider(minimum=0, maximum=30, default=2, label="Beta(亮度增加的偏移量)"),
21
+ gr.inputs.Slider(minimum=0, maximum=2, default=1.16, label="Saturation Factor(饱和度调整因子,大于1增加饱和度,小于1减少饱和度)")],
22
+ outputs="image"
23
+ )
24
+
25
+ iface.launch()