lappemic commited on
Commit
2a39662
1 Parent(s): 3caf593

try tab approach

Browse files
Files changed (1) hide show
  1. app.py +14 -33
app.py CHANGED
@@ -6,35 +6,23 @@ import kornia as K
6
  from kornia.core import Tensor
7
 
8
 
9
- def filters_without(file, blur_pool2d, box_blur, gaussian_blur2d, max_blur_pool2d, median_blur):
10
  # load the image using the rust backend
11
  img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32)
12
  img = img[None] # 1xCxHxW / fp32 / [0, 1]
13
 
14
- # apply tensor image enhancement
15
  x_out: Tensor = K.filters.box_blur(img, (int(box_blur), int(box_blur)))
16
- x_out = K.filters.gaussian_blur2d(x_out,
17
- (int(gaussian_blur2d), int(gaussian_blur2d)),
18
- (float(gaussian_blur2d), float(gaussian_blur2d)))
19
- x_out = K.filters.max_blur_pool2d(x_out, int(max_blur_pool2d))
20
- x_out = K.filters.median_blur(x_out, (int(median_blur), int(median_blur)))
21
-
22
  return K.utils.tensor_to_image(x_out)
23
 
24
- def filters_with(file, blur_pool2d, box_blur, gaussian_blur2d, max_blur_pool2d, median_blur):
25
  # load the image using the rust backend
26
  img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32)
27
  img = img[None] # 1xCxHxW / fp32 / [0, 1]
28
 
29
  # apply tensor image enhancement
30
  x_out: Tensor = K.filters.blur_pool2d(x_out, int(blur_pool2d))
31
- x_out = K.filters.box_blur(img, (int(box_blur), int(box_blur)))
32
- x_out = K.filters.gaussian_blur2d(x_out,
33
- (int(gaussian_blur2d), int(gaussian_blur2d)),
34
- (float(gaussian_blur2d), float(gaussian_blur2d)))
35
- x_out = K.filters.max_blur_pool2d(x_out, int(max_blur_pool2d))
36
- x_out = K.filters.median_blur(x_out, (int(median_blur), int(median_blur)))
37
-
38
  return K.utils.tensor_to_image(x_out)
39
 
40
 
@@ -43,49 +31,42 @@ examples = [
43
  ["examples/pikachu.jpg", 1, 1, 1, 1, 1],
44
  ]
45
 
46
- without_downsampling_demo = gr.Interface(
47
- filters_without,
48
  [
49
  gr.inputs.Image(type="file"),
50
  gr.inputs.Slider(minimum=1, maximum=10, step=1, default=1, label="Box Blur"),
51
- gr.inputs.Slider(minimum=1, maximum=21, step=2, default=1, label="Gaussian Blur"),
52
- gr.inputs.Slider(minimum=1, maximum=20, step=1, default=1, label="Max Pool"),
53
- gr.inputs.Slider(minimum=1, maximum=5, step=2, default=1, label="Median Blur"),
54
  ],
55
  "image",
56
  examples=examples,
57
  # title=title,
58
- description= 'If you want to use the filters with downsampled image, use tab "With image downsampling"',
59
  # article=article,
60
  live=True
61
  )
62
 
63
- with_downsampling_demo = gr.Interface(
64
- filters_with,
65
  [
66
  gr.inputs.Image(type="file"),
67
  gr.inputs.Slider(minimum=1, maximum=10, step=1, default=1, label="Blur Pool"),
68
- gr.inputs.Slider(minimum=1, maximum=10, step=1, default=1, label="Box Blur"),
69
- gr.inputs.Slider(minimum=1, maximum=21, step=2, default=1, label="Gaussian Blur"),
70
- gr.inputs.Slider(minimum=1, maximum=20, step=1, default=1, label="Max Pool"),
71
- gr.inputs.Slider(minimum=1, maximum=5, step=2, default=1, label="Median Blur"),
72
  ],
73
  "image",
74
  examples=examples,
75
  # title=title,
76
- description = 'Blur Pooling downsamples the image in the default setting!',
77
  # article=article,
78
  live=True
79
  )
80
 
81
  demo = gr.TabbedInterface(
82
  [
83
- without_downsampling_demo,
84
- with_downsampling_demo
85
  ],
86
  [
87
- "Without image downsampling",
88
- "With image downsampling"
89
  ]
90
  )
91
 
 
6
  from kornia.core import Tensor
7
 
8
 
9
+ def box_blur_fn(file, box_blur):
10
  # load the image using the rust backend
11
  img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32)
12
  img = img[None] # 1xCxHxW / fp32 / [0, 1]
13
 
 
14
  x_out: Tensor = K.filters.box_blur(img, (int(box_blur), int(box_blur)))
15
+
 
 
 
 
 
16
  return K.utils.tensor_to_image(x_out)
17
 
18
+ def blur_pool2d_fn(file, blur_pool2d):
19
  # load the image using the rust backend
20
  img: Tensor = K.io.load_image(file.name, K.io.ImageLoadType.RGB32)
21
  img = img[None] # 1xCxHxW / fp32 / [0, 1]
22
 
23
  # apply tensor image enhancement
24
  x_out: Tensor = K.filters.blur_pool2d(x_out, int(blur_pool2d))
25
+
 
 
 
 
 
 
26
  return K.utils.tensor_to_image(x_out)
27
 
28
 
 
31
  ["examples/pikachu.jpg", 1, 1, 1, 1, 1],
32
  ]
33
 
34
+ box_blur_fn_demo = gr.Interface(
35
+ box_blur_fn,
36
  [
37
  gr.inputs.Image(type="file"),
38
  gr.inputs.Slider(minimum=1, maximum=10, step=1, default=1, label="Box Blur"),
 
 
 
39
  ],
40
  "image",
41
  examples=examples,
42
  # title=title,
43
+ # description=description,
44
  # article=article,
45
  live=True
46
  )
47
 
48
+ blur_pool2d_fn_demo = gr.Interface(
49
+ blur_pool2d_fn,
50
  [
51
  gr.inputs.Image(type="file"),
52
  gr.inputs.Slider(minimum=1, maximum=10, step=1, default=1, label="Blur Pool"),
 
 
 
 
53
  ],
54
  "image",
55
  examples=examples,
56
  # title=title,
57
+ # description=description,
58
  # article=article,
59
  live=True
60
  )
61
 
62
  demo = gr.TabbedInterface(
63
  [
64
+ box_blur_fn_demo,
65
+ blur_pool2d_fn_demo
66
  ],
67
  [
68
+ "Box Blur",
69
+ "Blur Pool"
70
  ]
71
  )
72