marclelarge commited on
Commit
196e2d0
1 Parent(s): 6b9a982

added webcam

Browse files
Files changed (1) hide show
  1. app.py +50 -27
app.py CHANGED
@@ -4,45 +4,68 @@ from utils import encoder, decoder, decoder_noise
4
  title = "**Playing with kNN for denoising**"
5
  description = """The encoder takes any image (on the top left) and remove a fraction of the pixels producing a noisy image (on the top right).
6
  The decoder takes a noisy image (on the bottom left) and achieves denoising using kNN where you can choose the number of neighbors k.
7
- You can directly use the decoder on the encoded image (if you used the encoder first!)."""
 
 
8
 
9
  demo = gr.Blocks()
10
 
11
  with demo:
12
  gr.Markdown(title)
13
  gr.Markdown(description)
14
- with gr.Row():
15
- with gr.Column():
16
- source_img = gr.Image(source="upload", type="filepath", label="init_img")
17
-
18
- noise = gr.Slider(label='noise', minimum = 0.5, maximum = 1, step = .005, value = .95)
19
- with gr.Row():
20
- b1 = gr.Button("Encoder")
21
- examples_encoder = gr.Examples([["images/joconde.png"], ["images/braque.png"], ["images/Voronoy.jpg"]], inputs=[source_img])
22
- with gr.Column():
23
- encoded_img = gr.Image()
24
- with gr.Row():
25
- bt = gr.Button("Decoder noisy image above")
 
 
26
 
27
-
28
 
29
-
30
- with gr.Row():
31
- with gr.Column():
32
-
33
- noise_img = gr.Image(source="upload", type="filepath", label="init_img")
34
- k = gr.Slider(label='k', minimum = 1, maximum = 10, step = 1, value = 1)
35
- with gr.Row():
36
- b2 = gr.Button("Decoder")
37
- examples_decoder = gr.Examples([["images/afghan_coded.png"], ["images/wave_coded.png"], ["images/spider_coded.png"]], inputs=[noise_img])
38
- #bt = gr.Button("Decoder noisy image above")
39
- with gr.Column():
40
- decoded_img = gr.Image()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
 
43
  b1.click(encoder, inputs=[source_img, noise], outputs=encoded_img)
44
  b2.click(decoder, inputs=[noise_img,k], outputs=decoded_img)
45
  bt.click(decoder_noise, inputs=[encoded_img,k], outputs=decoded_img)
46
-
 
47
 
48
  demo.launch()
 
4
  title = "**Playing with kNN for denoising**"
5
  description = """The encoder takes any image (on the top left) and remove a fraction of the pixels producing a noisy image (on the top right).
6
  The decoder takes a noisy image (on the bottom left) and achieves denoising using kNN where you can choose the number of neighbors k.
7
+ You can directly use the decoder on the encoded image (if you used the encoder first!).
8
+ If you want to use the webcam (instead of upload), click on the webcam Tab.
9
+ """
10
 
11
  demo = gr.Blocks()
12
 
13
  with demo:
14
  gr.Markdown(title)
15
  gr.Markdown(description)
16
+ with gr.Tab("upload"):
17
+ with gr.Row():
18
+ with gr.Column():
19
+ source_img = gr.Image(source="upload", type="filepath", label="init_img")
20
+
21
+ noise = gr.Slider(label='noise', minimum = 0.5, maximum = 1, step = .005, value = .95)
22
+ with gr.Row():
23
+ b1 = gr.Button("Encoder")
24
+ examples_encoder = gr.Examples([["images/joconde.png"], ["images/braque.png"], ["images/Voronoy.jpg"]], inputs=[source_img])
25
+ with gr.Column():
26
+ encoded_img = gr.Image()
27
+ with gr.Row():
28
+ bt = gr.Button("Decoder noisy image above")
29
+
30
 
 
31
 
32
+
33
+ with gr.Row():
34
+ with gr.Column():
35
+
36
+ noise_img = gr.Image(source="upload", type="filepath", label="init_img")
37
+ k = gr.Slider(label='k', minimum = 1, maximum = 10, step = 1, value = 1)
38
+ with gr.Row():
39
+ b2 = gr.Button("Decoder")
40
+ examples_decoder = gr.Examples([["images/afghan_coded.png"], ["images/wave_coded.png"], ["images/spider_coded.png"]], inputs=[noise_img])
41
+ #bt = gr.Button("Decoder noisy image above")
42
+ with gr.Column():
43
+ decoded_img = gr.Image()
44
+
45
+ with gr.Tab("webcam"):
46
+ with gr.Row():
47
+ with gr.Column():
48
+ source_img_w = gr.Image(source="webcam", type="filepath", label="init_img")
49
+
50
+ noise_w = gr.Slider(label='noise', minimum = 0.5, maximum = 1, step = .005, value = .95)
51
+ with gr.Row():
52
+ b1_w = gr.Button("Encoder")
53
+ examples_encoder_w = gr.Examples([["images/joconde.png"], ["images/Voronoy.jpg"]], inputs=[source_img_w])
54
+ with gr.Column():
55
+ encoded_img_w = gr.Image()
56
+ k_w = gr.Slider(label='k', minimum = 1, maximum = 10, step = 1, value = 1)
57
+ with gr.Row():
58
+ bt_w = gr.Button("Decoder")
59
+ examples_decoder_w = gr.Examples([["images/afghan_coded.png"], ["images/spider_coded.png"]], inputs=[encoded_img_w])
60
+ #bt = gr.Button("Decoder noisy image above")
61
+ with gr.Column():
62
+ decoded_img_w = gr.Image()
63
 
64
 
65
  b1.click(encoder, inputs=[source_img, noise], outputs=encoded_img)
66
  b2.click(decoder, inputs=[noise_img,k], outputs=decoded_img)
67
  bt.click(decoder_noise, inputs=[encoded_img,k], outputs=decoded_img)
68
+ b1_w.click(encoder, inputs=[source_img_w, noise_w], outputs=encoded_img_w)
69
+ bt_w.click(decoder_noise, inputs=[encoded_img_w,k_w], outputs=decoded_img_w)
70
 
71
  demo.launch()