Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,32 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
import numpy
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
rng = range(1,225)
|
| 7 |
-
sobel_verticle =
|
| 8 |
[-1,0,1],
|
| 9 |
-
[-1,0,1]])
|
| 10 |
|
| 11 |
-
sobel_horizontal =
|
| 12 |
[ 0, 0, 0],
|
| 13 |
-
[ 1, 1, 1]])
|
| 14 |
|
| 15 |
-
laplacian =
|
| 16 |
[-1, 5,-1],
|
| 17 |
-
[ 0,-1, 0]])
|
| 18 |
|
| 19 |
-
average =
|
| 20 |
[1/9,1/9, 1/9],
|
| 21 |
-
[1/9,1/9, 1/9]])
|
| 22 |
|
| 23 |
|
| 24 |
-
weighted_average =
|
| 25 |
[2/16,4/16, 2/16],
|
| 26 |
-
[1/16,2/16, 1/16]])
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
def apply_kernel(img, row, col, kernel):
|
| 30 |
-
return (img[row-1:row+2,col-1:col+2] * kernel).sum()
|
| 31 |
|
| 32 |
def convolve(img, kernel):
|
| 33 |
-
|
| 34 |
-
ch1 = torch.tensor([[apply_kernel(ch1, i,j,kernel) for j in rng] for i in rng])
|
| 35 |
-
ch2 = torch.tensor([[apply_kernel(ch2, i,j,kernel) for j in rng] for i in rng])
|
| 36 |
-
ch3 = torch.tensor([[apply_kernel(ch3, i,j,kernel) for j in rng] for i in rng])
|
| 37 |
-
out_img = (torch.stack((ch1,ch2,ch3),-1)).numpy()
|
| 38 |
return Image.fromarray(out_img)
|
| 39 |
|
| 40 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import cv2
|
| 3 |
+
import numpy as np
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
rng = range(1,225)
|
| 7 |
+
sobel_verticle = np.array([[-1,0,1],
|
| 8 |
[-1,0,1],
|
| 9 |
+
[-1,0,1]])
|
| 10 |
|
| 11 |
+
sobel_horizontal = np.array([[-1,-1,11],
|
| 12 |
[ 0, 0, 0],
|
| 13 |
+
[ 1, 1, 1]])
|
| 14 |
|
| 15 |
+
laplacian = np.array([[ 0,-1, 0],
|
| 16 |
[-1, 5,-1],
|
| 17 |
+
[ 0,-1, 0]])
|
| 18 |
|
| 19 |
+
average = np.array([[1/9,1/9, 1/9],
|
| 20 |
[1/9,1/9, 1/9],
|
| 21 |
+
[1/9,1/9, 1/9]])
|
| 22 |
|
| 23 |
|
| 24 |
+
weighted_average = np.array([[1/16,2/16, 1/16],
|
| 25 |
[2/16,4/16, 2/16],
|
| 26 |
+
[1/16,2/16, 1/16]])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
def convolve(img, kernel):
|
| 29 |
+
out_img = cv2.filter2D(src=img, kernel=kernel)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
return Image.fromarray(out_img)
|
| 31 |
|
| 32 |
|