lappemic
update app.py
530752c
raw
history blame
2.26 kB
# created with great guidance from https://github.com/NimaBoscarino
import gradio as gr
import kornia as K
from kornia.core import Tensor
def filters(file, box_blur, blur_pool2d, gaussian_blur2d, max_blur_pool2d, median_blur):
# load the image using the rust backend
img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32)
img = img[None] # 1xCxHxW / fp32 / [0, 1]
# apply tensor image enhancement
x_out: Tensor = K.filters.box_blur(img, float(box_blur))
x_out = K.filters.blur_pool2d(x_out, float(blur_pool2d))
x_out = K.filters.gaussian_blur2d(x_out, float(gaussian_blur2d))
x_out = K.filters.max_blur_pool2d(x_out, float(max_blur_pool2d))
x_out = K.filters.median_blur(x_out, float(median_blur))
return K.utils.tensor_to_image(x_out)
examples = [
["examples/ninja_turtles.jpg", 0, 1, 1, 1, 0],
["examples/kitty.jpg", 0, 1, 1, 1, 0],
]
title = "Kornia Image Filters"
description = "<p style='text-align: center'>This is a Gradio demo for Kornia's Image Filters.</p><p style='text-align: center'>To use it, simply upload your image, or click one of the examples to load them, and use the sliders to enhance! Read more at the links at the bottom.</p>"
article = "<p style='text-align: center'><a href='https://kornia.readthedocs.io/en/latest/' target='_blank'>Kornia Docs</a> | <a href='https://github.com/kornia/kornia' target='_blank'>Kornia Github Repo</a> | <a href='https://kornia-tutorials.readthedocs.io/en/latest/image_enhancement.html' target='_blank'>Kornia Enhancements Tutorial</a></p>"
iface = gr.Interface(
enhance,
[
gr.inputs.Image(type="file"),
gr.inputs.Slider(minimum=0, maximum=1, step=0.1, default=0, label="Box Blur"),
gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=1, label="Blur Pool"),
gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=1, label="Gaussian Blur"),
gr.inputs.Slider(minimum=0, maximum=1, step=0.1, default=1, label="Max Pool"),
gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=0, label="Median Blur"),
],
"image",
examples=examples,
# title=title,
# description=description,
# article=article,
live=True
)
iface.launch()