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.
91 lines
4.0 KiB
91 lines
4.0 KiB
import gradio as gr
|
|
from img_enhancement import Image_enhancement
|
|
|
|
"""1.3 对图像进行频率像素点操作:模糊、锐化、添加噪声、边缘检测等操作"""
|
|
|
|
# 类实例化
|
|
img_enhance = Image_enhancement()
|
|
|
|
def img_handle_3():
|
|
def pridict_1(query_image=None,method_1="高斯滤波",count=3):
|
|
if method_1 == "高斯滤波":
|
|
img_mohu = img_enhance.Gaussblur(query_image,count)
|
|
elif method_1 == "随机模糊":
|
|
img_mohu = img_enhance.Blur(query_image, count)
|
|
else: # 中值滤波
|
|
img_mohu = img_enhance.Medianblur(query_image, count=5)
|
|
return img_mohu
|
|
|
|
def pridict_2(query_image=None,method_2="robert"):
|
|
if method_2=="sobel":
|
|
img_out = img_enhance.sobel(query_image)
|
|
elif method_2=="Prewitt":
|
|
img_out = img_enhance.Prewitt(query_image)
|
|
else:#robert
|
|
img_out = img_enhance.robert(query_image)
|
|
return img_out
|
|
|
|
def pridict_3(query_image=None,method_3="高斯噪声",mean=0,sigma=30,percentage=10):
|
|
if method_3=="高斯噪声":
|
|
img_noise = img_enhance.add_gaussian_noise(query_image,mean,sigma)
|
|
elif method_3=="椒盐噪声":
|
|
img_noise = img_enhance.add_salt_and_pepper_noise(query_image, percentage)
|
|
else:# 均值噪声
|
|
img_noise = img_enhance.add_mean_noise(query_image, mean, sigma)
|
|
return img_noise
|
|
|
|
def pridict_4(query_image=None,method_4="yes"):
|
|
if method_4=="yes":
|
|
img_detect= img_enhance.Canny(query_image)
|
|
else: #no
|
|
img_detect = query_image
|
|
return img_detect
|
|
|
|
title = "<h1 align='center'>图像处理操作3:频率像素点操作</h1>"
|
|
description = "3.对图像进行频率像素点操作:模糊、锐化、添加噪声、边缘检测等操作"
|
|
|
|
with gr.Blocks() as demo:
|
|
gr.Markdown(title)
|
|
gr.Markdown(description)
|
|
with gr.Row():
|
|
with gr.Column(scale=1):
|
|
img = gr.components.Image(label="图片")
|
|
method_1 = gr.components.Radio(label="模糊算法选择", choices=["高斯滤波", "随机模糊","中值滤波"],
|
|
value="高斯滤波", )
|
|
count = gr.components.Slider(minimum=0, maximum=8, step=1, value=3, label="模糊次数")
|
|
|
|
btn_1 = gr.Button("模糊处理", )
|
|
|
|
method_2 = gr.components.Radio(label="算子选择", choices=["sobel", "Prewitt","robert"],
|
|
value="robert",)
|
|
btn_2 = gr.Button("锐化处理", )
|
|
|
|
method_3 = gr.components.Radio(label="添加噪声类型选择", choices=["高斯噪声", "椒盐噪声", "均值噪声"],
|
|
value="高斯噪声", )
|
|
mean = gr.components.Slider(minimum=0, maximum=100, step=2, value=0, label="均值")
|
|
sigma = gr.components.Slider(minimum=0, maximum=100, step=2, value=30, label="标准差")
|
|
percentage = gr.components.Slider(minimum=0, maximum=100, step=5, value=30, label="百分比")
|
|
btn_3 = gr.Button("添加噪声", )
|
|
|
|
method_4 = gr.components.Radio(label="是否边缘检测", choices=["yes","no"],
|
|
value="yes", )
|
|
btn_4 = gr.Button("边缘检测", )
|
|
|
|
|
|
with gr.Column(scale=1):
|
|
out = gr.components.Image(label="处理后的图片为", height="auto")
|
|
|
|
btn_1.click(fn=pridict_1, inputs=[img, method_1,count], outputs=out)
|
|
btn_2.click(fn=pridict_2, inputs=[img, method_2], outputs=out)
|
|
btn_3.click(fn=pridict_3, inputs=[img, method_3,mean,sigma,percentage], outputs=out)
|
|
btn_4.click(fn=pridict_4, inputs=[img,method_4], outputs=out)
|
|
|
|
return demo
|
|
|
|
|
|
if __name__ == "__main__":
|
|
with gr.TabbedInterface(
|
|
[img_handle_3()],
|
|
["图像处理3:频率像素点操作"],
|
|
) as demo:
|
|
demo.launch() |