Spaces:
Sleeping
Sleeping
tomaseo2022
commited on
Commit
•
1c1298c
1
Parent(s):
ae760b6
Upload 5 files
Browse files- README.md +11 -0
- app.py +49 -0
- gitattributes.txt +27 -0
- packages.txt +1 -0
- requirements.txt +4 -0
README.md
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Kornia Image Enhancement
|
3 |
+
emoji: 🪄
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: purple
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.3.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
+
---
|
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
import kornia as K
|
4 |
+
from kornia.core import Tensor
|
5 |
+
|
6 |
+
|
7 |
+
def enhance(file, brightness, contrast, saturation, gamma, hue):
|
8 |
+
# load the image using the rust backend
|
9 |
+
img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32)
|
10 |
+
img = img[None] # 1xCxHxW / fp32 / [0, 1]
|
11 |
+
|
12 |
+
# apply tensor image enhancement
|
13 |
+
x_out: Tensor = K.enhance.adjust_brightness(img, float(brightness))
|
14 |
+
x_out = K.enhance.adjust_contrast(x_out, float(contrast))
|
15 |
+
x_out = K.enhance.adjust_saturation(x_out, float(saturation))
|
16 |
+
x_out = K.enhance.adjust_gamma(x_out, float(gamma))
|
17 |
+
x_out = K.enhance.adjust_hue(x_out, float(hue))
|
18 |
+
|
19 |
+
return K.utils.tensor_to_image(x_out)
|
20 |
+
|
21 |
+
|
22 |
+
examples = [
|
23 |
+
["examples/ninja_turtles.jpg", 0, 1, 1, 1, 0],
|
24 |
+
["examples/kitty.jpg", 0, 1, 1, 1, 0],
|
25 |
+
]
|
26 |
+
|
27 |
+
title = "Kornia Image Enhancements"
|
28 |
+
description = "<p style='text-align: center'>This is a Gradio demo for Kornia's Image Enhancements.</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>"
|
29 |
+
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>"
|
30 |
+
|
31 |
+
iface = gr.Interface(
|
32 |
+
enhance,
|
33 |
+
[
|
34 |
+
gr.inputs.Image(type="file"),
|
35 |
+
gr.inputs.Slider(minimum=0, maximum=1, step=0.1, default=0, label="Brightness"),
|
36 |
+
gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=1, label="Contrast"),
|
37 |
+
gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=1, label="Saturation"),
|
38 |
+
gr.inputs.Slider(minimum=0, maximum=1, step=0.1, default=1, label="Gamma"),
|
39 |
+
gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=0, label="Hue"),
|
40 |
+
],
|
41 |
+
"image",
|
42 |
+
examples=examples,
|
43 |
+
# title=title,
|
44 |
+
# description=description,
|
45 |
+
# article=article,
|
46 |
+
live=True
|
47 |
+
)
|
48 |
+
|
49 |
+
iface.launch()
|
gitattributes.txt
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
20 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
packages.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
python3-opencv
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
kornia
|
2 |
+
kornia_rs
|
3 |
+
opencv-python
|
4 |
+
torch
|