Spaces:
Running
Running
Commit
•
aeda751
1
Parent(s):
fa0d071
exemples
Browse files- app.py +9 -2
- images/Voronoy.jpg +0 -0
- images/afghan_coded.png +0 -0
- images/braque.png +0 -0
- images/joconde.png +0 -0
- images/spider_coded.png +0 -0
- images/wave_coded.png +0 -0
- utils.py +3 -3
app.py
CHANGED
@@ -1,12 +1,16 @@
|
|
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
|
|
|
|
|
6 |
|
7 |
demo = gr.Blocks()
|
8 |
|
9 |
with demo:
|
|
|
|
|
10 |
with gr.Row():
|
11 |
with gr.Column():
|
12 |
source_img = gr.Image(source="upload", type="filepath", label="init_img")
|
@@ -14,10 +18,12 @@ with demo:
|
|
14 |
noise = gr.Slider(label='noise', minimum = 0.5, maximum = 1, step = .005, value = .95)
|
15 |
with gr.Row():
|
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 |
|
@@ -28,6 +34,7 @@ with demo:
|
|
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()
|
|
|
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 (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 (iy you used the encoder)."""
|
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")
|
|
|
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 |
|
|
|
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()
|
images/Voronoy.jpg
ADDED
![]() |
images/afghan_coded.png
ADDED
![]() |
images/braque.png
ADDED
![]() |
images/joconde.png
ADDED
![]() |
images/spider_coded.png
ADDED
![]() |
images/wave_coded.png
ADDED
![]() |
utils.py
CHANGED
@@ -34,7 +34,7 @@ def encoder_cp(img,color_points):
|
|
34 |
img2.putpixel((p[0],p[1]),(t[0],t[1],t[2]))
|
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)
|
@@ -77,12 +77,12 @@ def restore(img, k, color_points, noise_points):
|
|
77 |
img.putpixel((p[0],p[1]),(r_m,v_m,b_m))
|
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)
|
|
|
34 |
img2.putpixel((p[0],p[1]),(t[0],t[1],t[2]))
|
35 |
return img2
|
36 |
|
37 |
+
def encoder(img,p=0.95):
|
38 |
img = resize(VALUE,img)
|
39 |
mask = get_mask(img,p)
|
40 |
c_p, n_p = generate_points(mask)
|
|
|
77 |
img.putpixel((p[0],p[1]),(r_m,v_m,b_m))
|
78 |
return img
|
79 |
|
80 |
+
def decoder(img,k=1):
|
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=1):
|
86 |
img = Image.fromarray(img)
|
87 |
#img = resize(VALUE,img)
|
88 |
c_p, n_p = get_points(img)
|