NimaBoscarino commited on
Commit
2aac19a
1 Parent(s): 3971c6b

Add initial demo with basic enhancements

Browse files
Files changed (6) hide show
  1. README.md +2 -4
  2. app.py +47 -0
  3. examples/kitty.jpg +0 -0
  4. examples/ninja_turtles.jpg +0 -0
  5. packages.txt +1 -0
  6. requirements.txt +3 -0
README.md CHANGED
@@ -1,13 +1,11 @@
1
  ---
2
  title: Kornia Image Enhancement
3
- emoji: 📈
4
  colorFrom: red
5
  colorTo: purple
6
- sdk: gradio
7
  sdk_version: 2.9.0
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
11
  ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
 
1
  ---
2
  title: Kornia Image Enhancement
3
+ emoji: 🪄
4
  colorFrom: red
5
  colorTo: purple
6
+ sdk: green
7
  sdk_version: 2.9.0
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
11
  ---
 
 
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+
4
+ import torch
5
+ import kornia as K
6
+
7
+ def load_torch_image(fname):
8
+ img = K.image_to_tensor(fname, False).float() / 255.
9
+ img = K.color.bgr_to_rgb(img)
10
+ return img
11
+
12
+
13
+ def enhance(file, brightness, contrast, saturation, gamma, hue):
14
+ fname = file.name
15
+ im = cv2.imread(fname)
16
+ img = load_torch_image(im)
17
+
18
+ x_out: torch.Tensor = K.enhance.adjust_brightness(img, float(brightness))
19
+ x_out = K.enhance.adjust_contrast(x_out, float(contrast))
20
+ x_out = K.enhance.adjust_saturation(x_out, float(saturation))
21
+ x_out = K.enhance.adjust_gamma(x_out, float(gamma))
22
+ x_out = K.enhance.adjust_hue(x_out, float(hue))
23
+
24
+ return K.utils.tensor_to_image(x_out)
25
+
26
+
27
+ examples = [
28
+ ["examples/ninja_turtles.jpg", 0, 1, 1, 1, 0],
29
+ ["examples/kitty.jpg", 0, 1, 1, 1, 0],
30
+ ]
31
+
32
+ iface = gr.Interface(
33
+ enhance,
34
+ [
35
+ gr.inputs.Image(type="file"),
36
+ gr.inputs.Slider(minimum=0, maximum=1, step=0.1, default=0, label="Brightness"),
37
+ gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=1, label="Contrast"),
38
+ gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=1, label="Saturation"),
39
+ gr.inputs.Slider(minimum=0, maximum=1, step=0.1, default=1, label="Gamma"),
40
+ gr.inputs.Slider(minimum=0, maximum=4, step=0.1, default=0, label="Hue"),
41
+ ],
42
+ "image",
43
+ examples=examples,
44
+ live=True
45
+ )
46
+
47
+ iface.launch()
examples/kitty.jpg ADDED
examples/ninja_turtles.jpg ADDED
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ python3-opencv
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ kornia
2
+ opencv-python
3
+ torch