Spaces:
Runtime error
Runtime error
import gradio as gr | |
import cv2 | |
import numpy as np | |
def enhance_image(opencv_image, alpha, beta, saturation_factor): | |
image = opencv_image | |
# 调整亮度和对比度 | |
image = cv2.convertScaleAbs(image, alpha=alpha, beta=beta) | |
# 将图像转换为HSV颜色空间 | |
hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) | |
# 调整饱和度 | |
hsv_image[:, :, 1] = np.clip(hsv_image[:, :, 1] * saturation_factor, 0, 255).astype(np.uint8) | |
# 将图像转换回BGR颜色空间 | |
output_image = cv2.cvtColor(hsv_image, cv2.COLOR_HSV2BGR) | |
return output_image | |
iface = gr.Interface( | |
fn=enhance_image, | |
inputs=["image", gr.inputs.Slider(minimum=0, maximum=2, default=1.02, label="Alpha(对比度增加的比例因子)"), | |
gr.inputs.Slider(minimum=0, maximum=30, default=2, label="Beta(亮度增加的偏移量)"), | |
gr.inputs.Slider(minimum=0, maximum=2, default=1.16, label="Saturation Factor(饱和度调整因子,大于1增加饱和度,小于1减少饱和度)")], | |
outputs="image" | |
) | |
iface.launch() | |