osanseviero HF staff commited on
Commit
247253a
1 Parent(s): fb1cd10

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -29
app.py CHANGED
@@ -1,48 +1,36 @@
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
 
 
1
  import gradio as gr
2
 
3
+ import cv2 as cv
4
+ import numpy as np
5
+ from matplotlib import pyplot as plt
6
 
7
 
8
+ def blur(file):
9
+ img = cv.imread('opencv-logo-white.png')
10
+ avg_blur = cv.blur(img,(5,5))
11
+ gaus_blur = cv.GaussianBlur(img,(5,5),0)
12
+ med_blur = cv.medianBlur(img,5)
13
 
14
+ return avg_blur, gaus_blur, med_blur
 
 
 
 
 
 
 
15
 
16
 
17
  examples = [
18
+ ["kitty.jpg"],
 
19
  ]
20
 
21
+ title = "OpenCV Blurring"
 
 
22
 
23
  iface = gr.Interface(
24
  enhance,
25
  [
26
+ gr.Image(type="file"),
 
 
 
 
 
27
  ],
28
+ [
29
+ gr.Image(label="Average Blur"),
30
+ gr.Image(label="Gaussian Blur"),
31
+ gr.Image(label="Median Blur"),
32
+ ]
33
  examples=examples,
 
 
 
34
  live=True
35
  )
36