lappemic commited on
Commit
5825d5b
1 Parent(s): 446c261

Initial commit (change from personal space)

Browse files
Files changed (4) hide show
  1. .DS_Store +0 -0
  2. app.py +53 -0
  3. packages.txt +1 -0
  4. requirements.txt +4 -0
.DS_Store ADDED
Binary file (6.15 kB). View file
 
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # created with great guidance from https://github.com/NimaBoscarino
2
+
3
+ import gradio as gr
4
+
5
+ import kornia as K
6
+ from kornia.core import Tensor
7
+
8
+
9
+ def filters(file, box_blur, blur_pool2d, gaussian_blur2d, max_blur_pool2d, median_blur):
10
+ # load the image using the rust backend
11
+ img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32)
12
+ img = img[None] # 1xCxHxW / fp32 / [0, 1]
13
+
14
+ # apply tensor image enhancement
15
+ x_out: Tensor = K.filters.box_blur(img, (int(box_blur), int(box_blur)))
16
+ x_out = K.filters.blur_pool2d(x_out, int(blur_pool2d))
17
+ x_out = K.filters.gaussian_blur2d(x_out,
18
+ (int(gaussian_blur2d), int(gaussian_blur2d)),
19
+ (float(gaussian_blur2d), float(gaussian_blur2d)))
20
+ x_out = K.filters.max_blur_pool2d(x_out, int(max_blur_pool2d))
21
+ x_out = K.filters.median_blur(x_out, (int(median_blur), int(median_blur)))
22
+
23
+ return K.utils.tensor_to_image(x_out)
24
+
25
+
26
+ examples = [
27
+ ["examples/ninja_turtles.jpg", 1, 1, 1, 1, 1],
28
+ ["examples/kitty.jpg", 1, 1, 1, 1, 1],
29
+ ]
30
+
31
+ title = "Kornia Image Filters"
32
+ 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>"
33
+ 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>"
34
+
35
+ iface = gr.Interface(
36
+ filters,
37
+ [
38
+ gr.inputs.Image(type="file"),
39
+ gr.inputs.Slider(minimum=1, maximum=10, step=1, default=1, label="Box Blur"),
40
+ gr.inputs.Slider(minimum=1, maximum=10, step=1, default=1, label="Blur Pool"),
41
+ gr.inputs.Slider(minimum=1, maximum=21, step=2, default=1, label="Gaussian Blur"),
42
+ gr.inputs.Slider(minimum=1, maximum=20, step=1, default=1, label="Max Pool"),
43
+ gr.inputs.Slider(minimum=1, maximum=5, step=2, default=1, label="Median Blur"),
44
+ ],
45
+ "image",
46
+ examples=examples,
47
+ # title=title,
48
+ # description=description,
49
+ # article=article,
50
+ live=True
51
+ )
52
+
53
+ iface.launch()
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