File size: 4,075 Bytes
5825d5b
 
 
 
 
 
 
 
346da5d
2a39662
5825d5b
 
 
 
e3c3f88
2a39662
5825d5b
 
346da5d
2a39662
3caf593
 
 
 
8efad9d
2a39662
3caf593
 
346da5d
8efad9d
 
 
 
 
 
 
 
 
 
 
 
346da5d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5825d5b
346da5d
5825d5b
cfa42c2
 
5825d5b
 
346da5d
 
 
2a39662
5825d5b
 
260f4a1
e3c3f88
 
 
 
2a39662
e3c3f88
 
 
 
346da5d
 
2a39662
e3c3f88
 
260f4a1
5825d5b
 
 
 
2a39662
5825d5b
 
 
 
346da5d
 
8efad9d
 
 
260f4a1
8efad9d
 
 
 
 
 
 
 
 
346da5d
 
 
 
 
260f4a1
346da5d
 
 
 
 
 
 
 
 
 
 
 
 
260f4a1
346da5d
 
 
 
 
 
 
 
 
 
 
e3c3f88
 
346da5d
 
 
 
 
e3c3f88
 
2a39662
346da5d
 
 
 
e3c3f88
 
 
 
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# created with great guidance from https://github.com/NimaBoscarino

import gradio as gr

import kornia as K
from kornia.core import Tensor


# Define Functions
def box_blur_fn(file, box_blur):      
    # load the image using the rust backend          
    img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32)
    img = img[None]  # 1xCxHxW / fp32 / [0, 1]

    x_out: Tensor = K.filters.box_blur(img, (int(box_blur), int(box_blur)))
    
    return K.utils.tensor_to_image(x_out)


def blur_pool2d_fn(file, blur_pool2d):      
    # load the image using the rust backend          
    img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32)
    img = img[None]  # 1xCxHxW / fp32 / [0, 1]

    x_out: Tensor = K.filters.blur_pool2d(img, int(blur_pool2d))
    
    return K.utils.tensor_to_image(x_out)


def gaussian_blur_fn(file, gaussian_blur2d):      
    # load the image using the rust backend          
    img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32)
    img = img[None]  # 1xCxHxW / fp32 / [0, 1]

    x_out: Tensor = K.filters.gaussian_blur2d(img, 
                                              (int(gaussian_blur2d), int(gaussian_blur2d)),
                                              (float(gaussian_blur2d), float(gaussian_blur2d)))
    
    return K.utils.tensor_to_image(x_out)


def max_blur_pool2d_fn(file, max_blur_pool2d):
    # load the image using the rust backend          
    img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32)
    img = img[None]  # 1xCxHxW / fp32 / [0, 1]

    x_out: Tensor = K.filters.max_blur_pool2d(img, int(max_blur_pool2d))
    
    return K.utils.tensor_to_image(x_out)


def median_blur_fn(file, median_blur):      
    # load the image using the rust backend          
    img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32)
    img = img[None]  # 1xCxHxW / fp32 / [0, 1]

    x_out: Tensor = K.filters.median_blur(img, (int(median_blur), int(median_blur)))

    return K.utils.tensor_to_image(x_out)


# Define Examples
examples = [
    ["examples/monkey.jpg", 1, 1, 1, 1, 1],
    ["examples/pikachu.jpg", 1, 1, 1, 1, 1],
]


# Define Demos
box_blur_demo = gr.Interface(
    box_blur_fn,
    [
        gr.inputs.Image(type="file"),
        gr.inputs.Slider(minimum=1, maximum=20, step=1, default=1, label="Box Blur")
    ],
    "image",
    examples=examples,
    # title=title,
    # description=description,
    # article=article,
    live=True
)


blur_pool2d_demo = gr.Interface(
    blur_pool2d_fn,
    [
        gr.inputs.Image(type="file"),
        gr.inputs.Slider(minimum=1, maximum=40, step=1, default=1, label="Blur Pool")
    ],
    "image",
    examples=examples,
    # title=title,
    # description=description,
    # article=article,
    live=True
)


gaussian_blur_demo = gr.Interface(
    gaussian_blur_fn,
    [
        gr.inputs.Image(type="file"),
        gr.inputs.Slider(minimum=1, maximum=25, step=2, default=1, label="Gaussian Blur")
    ],
    "image",
    examples=examples,
    # title=title,
    # description=description,
    # article=article,
    live=True
)


max_blur_pool2d_demo = gr.Interface(
    max_blur_pool2d_fn,
    [
        gr.inputs.Image(type="file"),
        gr.inputs.Slider(minimum=1, maximum=40, step=1, default=1, label="Max Pool")
    ],
    "image",
    examples=examples,
    # title=title,
    # description=description,
    # article=article,
    live=True
)

median_blur_demo = gr.Interface(
    median_blur_fn,
    [
        gr.inputs.Image(type="file"),
        gr.inputs.Slider(minimum=1, maximum=25, step=2, default=1, label="Median Blur")
    ],
    "image",
    examples=examples,
    # title=title,
    # description=description,
    # article=article,
    live=True
)


# Create Interface
demo = gr.TabbedInterface(
    [
      box_blur_demo,
      blur_pool2d_demo,
      gaussian_blur_demo,
      max_blur_pool2d_demo,
      median_blur_demo
    ], 
    [
      "Box Blur", 
      "Blur Pool",
      "Gaussian Blur",
      "Max Pool",
      "Median Blur"
    ]
)

demo.launch()