marclelarge commited on
Commit
fa0d071
1 Parent(s): 062685e

encoder-decoder

Browse files
Files changed (2) hide show
  1. app.py +6 -1
  2. utils.py +10 -4
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import gradio as gr
2
- from utils import encoder, decoder
3
 
4
  title = "Playing with kNN for denoising"
5
  description = "The encoder takes any image and remove a fraction of the pixels producing a noisy image. The decoder takes a noisy image and achieves denoising using kNN where you can choose k."
@@ -16,21 +16,26 @@ with demo:
16
  b1 = gr.Button("Encoder")
17
  with gr.Column():
18
  encoded_img = gr.Image()
 
 
19
 
20
 
21
 
22
  with gr.Row():
23
  with gr.Column():
 
24
  noise_img = gr.Image(source="upload", type="filepath", label="init_img")
25
  k = gr.Slider(label='k', minimum = 1, maximum = 10, step = 1, value = 1)
26
  with gr.Row():
27
  b2 = gr.Button("Decoder")
 
28
  with gr.Column():
29
  decoded_img = gr.Image()
30
 
31
 
32
  b1.click(encoder, inputs=[source_img, noise], outputs=encoded_img)
33
  b2.click(decoder, inputs=[noise_img,k], outputs=decoded_img)
 
34
 
35
 
36
  demo.launch()
 
1
  import gradio as gr
2
+ from utils import encoder, decoder, decoder_noise
3
 
4
  title = "Playing with kNN for denoising"
5
  description = "The encoder takes any image and remove a fraction of the pixels producing a noisy image. The decoder takes a noisy image and achieves denoising using kNN where you can choose k."
 
16
  b1 = gr.Button("Encoder")
17
  with gr.Column():
18
  encoded_img = gr.Image()
19
+ with gr.Row():
20
+ bt = gr.Button("Decoder noisy image above")
21
 
22
 
23
 
24
  with gr.Row():
25
  with gr.Column():
26
+
27
  noise_img = gr.Image(source="upload", type="filepath", label="init_img")
28
  k = gr.Slider(label='k', minimum = 1, maximum = 10, step = 1, value = 1)
29
  with gr.Row():
30
  b2 = gr.Button("Decoder")
31
+ #bt = gr.Button("Decoder noisy image above")
32
  with gr.Column():
33
  decoded_img = gr.Image()
34
 
35
 
36
  b1.click(encoder, inputs=[source_img, noise], outputs=encoded_img)
37
  b2.click(decoder, inputs=[noise_img,k], outputs=decoded_img)
38
+ bt.click(decoder_noise, inputs=[encoded_img,k], outputs=decoded_img)
39
 
40
 
41
  demo.launch()
utils.py CHANGED
@@ -6,7 +6,8 @@ VALUE = 512
6
 
7
  def resize(value,img):
8
  img = Image.open(img)
9
- img = img.resize((value,value), Image.Resampling.LANCZOS)
 
10
  return img
11
 
12
  def get_mask(img,p):
@@ -34,8 +35,7 @@ def encoder_cp(img,color_points):
34
  return img2
35
 
36
  def encoder(img,p):
37
- #img = resize(VALUE,img)
38
- img = Image.open(img)
39
  mask = get_mask(img,p)
40
  c_p, n_p = generate_points(mask)
41
  return encoder_cp(img, c_p)
@@ -78,6 +78,12 @@ def restore(img, k, color_points, noise_points):
78
  return img
79
 
80
  def decoder(img,k):
81
- img = Image.open(img)
 
 
 
 
 
 
82
  c_p, n_p = get_points(img)
83
  return restore(img,int(k),c_p,n_p)
 
6
 
7
  def resize(value,img):
8
  img = Image.open(img)
9
+ #img = img.resize((value,value), Image.Resampling.LANCZOS)
10
+ img.thumbnail((VALUE,VALUE), Image.Resampling.LANCZOS)
11
  return img
12
 
13
  def get_mask(img,p):
 
35
  return img2
36
 
37
  def encoder(img,p):
38
+ img = resize(VALUE,img)
 
39
  mask = get_mask(img,p)
40
  c_p, n_p = generate_points(mask)
41
  return encoder_cp(img, c_p)
 
78
  return img
79
 
80
  def decoder(img,k):
81
+ img = resize(VALUE,img)
82
+ c_p, n_p = get_points(img)
83
+ return restore(img,int(k),c_p,n_p)
84
+
85
+ def decoder_noise(img,k):
86
+ img = Image.fromarray(img)
87
+ #img = resize(VALUE,img)
88
  c_p, n_p = get_points(img)
89
  return restore(img,int(k),c_p,n_p)