File size: 1,615 Bytes
8386270
98d3fb1
 
f240077
8386270
43cb5ef
 
ddb49c7
 
 
 
 
 
 
 
43cb5ef
8386270
98d3fb1
8386270
0d73d25
ddb49c7
 
8386270
ddb49c7
 
 
746d2d7
ddb49c7
 
 
 
 
 
 
 
8386270
5a853eb
8386270
5a853eb
8386270
5a853eb
8386270
5a853eb
8386270
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import gradio as gr
import cv2
import numpy as np
from PIL import Image


def convolve(img, kernel):

    out_img = cv2.filter2D(src=img, ddepth =-1, kernel=kernel)
    out_img = cv2.cvtColor(out_img, cv2.COLOR_BGR2RGB)
    out_img = cv2.resize(out_img, (226,226))
    return Image.fromarray(out_img)


def app(img, filter):
    sobel_verticle = np.array([[-1,0,1],
                               [-1,0,1],
                               [-1,0,1]])
                            
    sobel_horizontal = np.array([[-1,-1,-1],
                                 [ 0, 0, 0],
                                 [ 1, 1, 1]])

    laplacian = np.array([[ 0,-1, 0],
                          [-1, 5,-1],
                          [ 0,-1, 0]])

    average = np.array([[1/9,1/9, 1/9],
                          [1/9,1/9, 1/9],
                          [1/9,1/9, 1/9]])


    weighted_average = np.array([[1/16,2/16, 1/16],
                                 [2/16,4/16, 2/16],
                                 [1/16,2/16, 1/16]])

    if filter =="sobel_verticle":
        return convolve(img, sobel_verticle)
    elif filter =="sobel_horizontal":
        return convolve(img, sobel_horizontal)
    elif filter == "laplacian":
        return convolve(img, laplacian)
    elif filter == "average":
        return convolve(img, average)
    else:
        return convolve(img, weighted_average)

demo = gr.Interface(
    app,
    [
        gr.Image(shape=(226, 226)),
        gr.Radio(["sobel_verticle", "sobel_horizontal", "laplacian", "average", "weighted_average"])
    
    ],
    gr.Image(shape=(226, 226)),
)
demo.launch()