You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
2.5 KiB
55 lines
2.5 KiB
5 months ago
|
import gradio as gr
|
||
|
from img_enhancement import Image_enhancement
|
||
|
|
||
|
"""1.2 对图像进行颜色空间变化:图片的对比度调整、灰度图转换、直方图均衡化"""
|
||
|
|
||
|
# 类实例化
|
||
|
img_enhance = Image_enhancement()
|
||
|
|
||
|
def img_handle_2():
|
||
|
def pridict_1(query_image=None,brightness=10,hue=10,contrast=10,saturation=10):
|
||
|
img_Color = img_enhance.ColorJitter(query_image, brightness,hue,saturation,contrast)
|
||
|
return img_Color
|
||
|
|
||
|
def pridict_2(query_image=None,method="灰度化"):
|
||
|
if method=="灰度化":
|
||
|
img_out = img_enhance.ToGray(query_image)
|
||
|
elif method=="直方图均衡化":
|
||
|
img_out = img_enhance.equalhist(query_image)
|
||
|
return img_out
|
||
|
|
||
|
title = "<h1 align='center'>图像处理操作2:颜色空间变化</h1>"
|
||
|
description = "2.对图像进行颜色空间变化:图片的对比度调整、灰度图转换、直方图均衡化" # "颜色空间变化:图片的对比度调整、灰度图转换、直方图均衡化;" "频率像素点操作:模糊、锐化、添加噪声、边缘检测等操作"
|
||
|
|
||
|
with gr.Blocks() as demo:
|
||
|
gr.Markdown(title)
|
||
|
gr.Markdown(description)
|
||
|
with gr.Row():
|
||
|
with gr.Column(scale=1):
|
||
|
img = gr.components.Image(label="图片")
|
||
|
brightness = gr.components.Slider(minimum=0, maximum=100, step=5, value=10, label="选择亮度")
|
||
|
hue = gr.components.Slider(minimum=0, maximum=100, step=5, value=10, label="选择色调")
|
||
|
contrast = gr.components.Slider(minimum=0, maximum=100, step=5, value=10, label="选择对比度")
|
||
|
saturation = gr.components.Slider(minimum=0, maximum=100, step=5, value=10, label="选择饱和度")
|
||
|
btn_1 = gr.Button("对比度调整", )
|
||
|
|
||
|
method = gr.components.Radio(label="算法选择", choices=["灰度化", "直方图均衡化"],
|
||
|
value="灰度化",)
|
||
|
btn_2 = gr.Button("点击转化", )
|
||
|
|
||
|
with gr.Column(scale=1):
|
||
|
out = gr.components.Image(label="处理后的图片为", height="auto")
|
||
|
|
||
|
btn_1.click(fn=pridict_1, inputs=[img, brightness,hue,contrast,saturation], outputs=out)
|
||
|
|
||
|
btn_2.click(fn=pridict_2, inputs=[img, method], outputs=out)
|
||
|
|
||
|
return demo
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
with gr.TabbedInterface(
|
||
|
[img_handle_2()],
|
||
|
["图像处理2:颜色空间变化"],
|
||
|
) as demo:
|
||
|
demo.launch()
|