Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,14 @@ from PIL import Image
|
|
5 |
|
6 |
|
7 |
def convolve(img, kernel):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
sobel_verticle = np.array([[-1,0,1],
|
9 |
[-1,0,1],
|
10 |
[-1,0,1]])
|
@@ -25,14 +33,27 @@ def convolve(img, kernel):
|
|
25 |
weighted_average = np.array([[1/16,2/16, 1/16],
|
26 |
[2/16,4/16, 2/16],
|
27 |
[1/16,2/16, 1/16]])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
return Image.fromarray(out_img)
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
-
def app(img, filter):
|
36 |
if filter =="sobel_verticle":
|
37 |
return convolve(img, sobel_verticle)
|
38 |
elif filter =="sobel_horizontal":
|
|
|
5 |
|
6 |
|
7 |
def convolve(img, kernel):
|
8 |
+
|
9 |
+
out_img = cv2.filter2D(src=img, ddepth =-1, kernel=kernel)
|
10 |
+
out_img = cv2.cvtColor(out_img, cv2.COLOR_BGR2RGB)
|
11 |
+
out_img = cv2.resize(out_img, (226,226))
|
12 |
+
return Image.fromarray(out_img)
|
13 |
+
|
14 |
+
|
15 |
+
def app(img, filter):
|
16 |
sobel_verticle = np.array([[-1,0,1],
|
17 |
[-1,0,1],
|
18 |
[-1,0,1]])
|
|
|
33 |
weighted_average = np.array([[1/16,2/16, 1/16],
|
34 |
[2/16,4/16, 2/16],
|
35 |
[1/16,2/16, 1/16]])
|
36 |
+
sobel_verticle = np.array([[-1,0,1],
|
37 |
+
[-1,0,1],
|
38 |
+
[-1,0,1]])
|
39 |
+
|
40 |
+
sobel_horizontal = np.array([[-1,-1,11],
|
41 |
+
[ 0, 0, 0],
|
42 |
+
[ 1, 1, 1]])
|
43 |
|
44 |
+
laplacian = np.array([[ 0,-1, 0],
|
45 |
+
[-1, 5,-1],
|
46 |
+
[ 0,-1, 0]])
|
|
|
47 |
|
48 |
+
average = np.array([[1/9,1/9, 1/9],
|
49 |
+
[1/9,1/9, 1/9],
|
50 |
+
[1/9,1/9, 1/9]])
|
51 |
+
|
52 |
+
|
53 |
+
weighted_average = np.array([[1/16,2/16, 1/16],
|
54 |
+
[2/16,4/16, 2/16],
|
55 |
+
[1/16,2/16, 1/16]])
|
56 |
|
|
|
57 |
if filter =="sobel_verticle":
|
58 |
return convolve(img, sobel_verticle)
|
59 |
elif filter =="sobel_horizontal":
|