File size: 1,230 Bytes
19a285e
 
 
495efc8
19a285e
 
 
 
 
 
 
 
495efc8
19a285e
 
495efc8
19a285e
 
b2997cc
 
19a285e
 
 
 
 
 
c3f97b9
 
19a285e
 
 
 
 
 
 
 
 
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
import gradio as gr

import kornia as K
from kornia.core import concatenate, Tensor

def rescale_aa(file, height, width):
    
    img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32)
    img = img[None]

    img_rescale: Tensor = K.geometry.rescale(img, (float(height),float(width)),antialias=False)
    img_rescale_aa: Tensor = K.geometry.rescale(img, (float(height),float(width)),antialias=True)
    img_out = concatenate([img_rescale, img_rescale_aa], -1)
    
    # when antialiasing , some values are going greater than 1 i.e 1.00001 which is giving error while displaying the output image,so clipping the output values from 0 to 1
    return K.utils.tensor_to_image(img_out.clamp_(0, 1))

examples = [
    ["examples/a.png",0.25,0.25],
    ["examples/iron_man.jpeg",0.25,0.25],
]

kornia_resizing_demo = gr.Interface(
    rescale_aa,
    [
        gr.inputs.Image(type="file"),
        gr.inputs.Slider(minimum=0.005, maximum=2, step=0.005, default=0.25, label="Height"),
        gr.inputs.Slider(minimum=0.005, maximum=2, step=0.005, default=0.25, label="Width")
    ],
    "image",
    examples=examples,
    live=False,
    enable_queue = True,
    allow_flagging = "never"
)

kornia_resizing_demo.launch()