shljessie commited on
Commit
0b50d99
·
1 Parent(s): e7320c7

update the tactile graphics

Browse files
Files changed (2) hide show
  1. app.py +70 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ import kornia as K
4
+ from kornia.core import Tensor
5
+
6
+ def edge_detection(filepath, detector):
7
+
8
+ img: Tensor = K.io.load_image(filepath, K.io.ImageLoadType.RGB32)
9
+ img = img[None]
10
+
11
+ x_gray = K.color.rgb_to_grayscale(img)
12
+
13
+
14
+ if detector == '1st order derivates in x':
15
+ grads: Tensor = K.filters.spatial_gradient(x_gray, order=1)
16
+ grads_x = grads[:, :, 0]
17
+ grads_y = grads[:, :, 1]
18
+
19
+ output = K.utils.tensor_to_image(1. - grads_x.clamp(0., 1.))
20
+
21
+ elif detector == '1st order derivates in y':
22
+ grads: Tensor = K.filters.spatial_gradient(x_gray, order=1)
23
+ grads_x = grads[:, :, 0]
24
+ grads_y = grads[:, :, 1]
25
+
26
+ output = K.utils.tensor_to_image(1. - grads_y.clamp(0., 1.))
27
+
28
+ elif detector == '2nd order derivatives in x':
29
+ grads: Tensor = K.filters.spatial_gradient(x_gray, order=2)
30
+ grads_x = grads[:, :, 0]
31
+ grads_y = grads[:, :, 1]
32
+
33
+ output = K.utils.tensor_to_image(1. - grads_x.clamp(0., 1.))
34
+
35
+ elif detector == '2nd order derivatives in y':
36
+ grads: Tensor = K.filters.spatial_gradient(x_gray, order=2)
37
+ grads_x = grads[:, :, 0]
38
+ grads_y = grads[:, :, 1]
39
+
40
+ output = K.utils.tensor_to_image(1. - grads_y.clamp(0., 1.))
41
+
42
+ elif detector == 'Sobel':
43
+ x_sobel: Tensor = K.filters.sobel(x_gray)
44
+ output = K.utils.tensor_to_image(1. - x_sobel)
45
+
46
+ elif detector == 'Laplacian':
47
+ x_laplacian: Tensor = K.filters.laplacian(x_gray, kernel_size=5)
48
+ output = K.utils.tensor_to_image(1. - x_laplacian.clamp(0., 1.))
49
+
50
+ else:
51
+ x_canny: Tensor = K.filters.canny(x_gray)[0]
52
+ output = K.utils.tensor_to_image(1. - x_canny.clamp(0., 1.0))
53
+
54
+ return output
55
+
56
+ title = "Tactile Graphic Generator"
57
+ description = "<p style='text-align: center'>To use it, simply upload your image. Press Enter, them click on the tactile graphic to download.</p>"
58
+
59
+ iface = gr.Interface(edge_detection,
60
+ [
61
+ gr.Image(type="filepath"),
62
+ gr.Dropdown(choices=["1st order derivates in x", "1st order derivates in y", "2nd order derivatives in x", "2nd order derivatives in y", "Sobel", "Laplacian", "Canny"])
63
+ ],
64
+ "image",
65
+ title=title,
66
+ description=description,
67
+
68
+ )
69
+
70
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ kornia
2
+ kornia_rs
3
+ opencv-python
4
+ torch