Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -7,11 +7,11 @@ import torch
|
|
7 |
import kornia as K
|
8 |
from kornia.core import Tensor
|
9 |
|
10 |
-
def edge_detection(
|
11 |
|
12 |
-
img_bgr: np.ndarray = cv2.imread(
|
13 |
|
14 |
-
x_bgr: torch.Tensor = K.utils.image_to_tensor(img_bgr)
|
15 |
x_bgr = x_bgr[None,...].float() / 255.
|
16 |
|
17 |
x_rgb: torch.Tensor = K.color.bgr_to_rgb(x_bgr)
|
@@ -19,28 +19,28 @@ def edge_detection(file, detector):
|
|
19 |
|
20 |
|
21 |
if detector == '1st order derivates in x':
|
22 |
-
grads: torch.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_x.clamp(0., 1.))
|
27 |
|
28 |
elif detector == '1st order derivates in y':
|
29 |
-
grads: torch.Tensor = K.filters.spatial_gradient(x_gray, order=1)
|
30 |
grads_x = grads[:, :, 0]
|
31 |
grads_y = grads[:, :, 1]
|
32 |
|
33 |
output = K.utils.tensor_to_image(1. - grads_y.clamp(0., 1.))
|
34 |
|
35 |
elif detector == '2nd order derivatives in x':
|
36 |
-
grads: torch.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_x.clamp(0., 1.))
|
41 |
|
42 |
elif detector == '2nd order derivatives in y':
|
43 |
-
grads: torch.Tensor = K.filters.spatial_gradient(x_gray, order=2)
|
44 |
grads_x = grads[:, :, 0]
|
45 |
grads_y = grads[:, :, 1]
|
46 |
|
|
|
7 |
import kornia as K
|
8 |
from kornia.core import Tensor
|
9 |
|
10 |
+
def edge_detection(filepath, detector):
|
11 |
|
12 |
+
img_bgr: np.ndarray = cv2.imread(filepath, cv2.IMREAD_COLOR)
|
13 |
|
14 |
+
x_bgr: torch.Tensor = K.utils.image_to_tensor(img_bgr)
|
15 |
x_bgr = x_bgr[None,...].float() / 255.
|
16 |
|
17 |
x_rgb: torch.Tensor = K.color.bgr_to_rgb(x_bgr)
|
|
|
19 |
|
20 |
|
21 |
if detector == '1st order derivates in x':
|
22 |
+
grads: torch.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_x.clamp(0., 1.))
|
27 |
|
28 |
elif detector == '1st order derivates in y':
|
29 |
+
grads: torch.Tensor = K.filters.spatial_gradient(x_gray, order=1)
|
30 |
grads_x = grads[:, :, 0]
|
31 |
grads_y = grads[:, :, 1]
|
32 |
|
33 |
output = K.utils.tensor_to_image(1. - grads_y.clamp(0., 1.))
|
34 |
|
35 |
elif detector == '2nd order derivatives in x':
|
36 |
+
grads: torch.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_x.clamp(0., 1.))
|
41 |
|
42 |
elif detector == '2nd order derivatives in y':
|
43 |
+
grads: torch.Tensor = K.filters.spatial_gradient(x_gray, order=2)
|
44 |
grads_x = grads[:, :, 0]
|
45 |
grads_y = grads[:, :, 1]
|
46 |
|