Spaces:
Sleeping
Sleeping
Julián Tachella
commited on
Commit
·
ba74db2
1
Parent(s):
a983c72
test
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import torch
|
|
4 |
import numpy as np
|
5 |
import PIL.Image
|
6 |
|
|
|
7 |
def pil_to_torch(image):
|
8 |
image = np.array(image)
|
9 |
image = image.transpose((2, 0, 1))
|
@@ -19,9 +20,14 @@ def torch_to_pil(image):
|
|
19 |
return image
|
20 |
|
21 |
|
22 |
-
def image_mod(image, noise_level):
|
23 |
image = pil_to_torch(image)
|
24 |
-
denoiser
|
|
|
|
|
|
|
|
|
|
|
25 |
noisy = image + torch.randn_like(image) * noise_level
|
26 |
estimated = denoiser(image, noise_level)
|
27 |
return torch_to_pil(noisy), torch_to_pil(estimated)
|
@@ -34,10 +40,11 @@ input_image_output = gr.Image(label='Input Image')
|
|
34 |
|
35 |
noise_levels = gr.Dropdown(choices=[0.1, 0.2, 0.3, 0.4, 0.5], value=0.1, label='Noise Level')
|
36 |
|
|
|
37 |
|
38 |
demo = gr.Interface(
|
39 |
image_mod,
|
40 |
-
inputs=[input_image, noise_levels],
|
41 |
outputs=[noise_image, output_images],
|
42 |
title="Image Denoising with DeepInverse",
|
43 |
)
|
|
|
4 |
import numpy as np
|
5 |
import PIL.Image
|
6 |
|
7 |
+
|
8 |
def pil_to_torch(image):
|
9 |
image = np.array(image)
|
10 |
image = image.transpose((2, 0, 1))
|
|
|
20 |
return image
|
21 |
|
22 |
|
23 |
+
def image_mod(image, noise_level, denoiser):
|
24 |
image = pil_to_torch(image)
|
25 |
+
if denoiser == 'DnCNN':
|
26 |
+
denoiser = dinv.models.DnCNN()
|
27 |
+
elif denoiser == 'MedianFilter':
|
28 |
+
denoiser = dinv.models.MedianFilter()
|
29 |
+
else:
|
30 |
+
raise ValueError("Invalid denoiser")
|
31 |
noisy = image + torch.randn_like(image) * noise_level
|
32 |
estimated = denoiser(image, noise_level)
|
33 |
return torch_to_pil(noisy), torch_to_pil(estimated)
|
|
|
40 |
|
41 |
noise_levels = gr.Dropdown(choices=[0.1, 0.2, 0.3, 0.4, 0.5], value=0.1, label='Noise Level')
|
42 |
|
43 |
+
denoiser = gr.Dropdown(choices=['DnCNN', 'MedianFilter'], value=0.1, label='DnCNN')
|
44 |
|
45 |
demo = gr.Interface(
|
46 |
image_mod,
|
47 |
+
inputs=[input_image, noise_levels, denoiser],
|
48 |
outputs=[noise_image, output_images],
|
49 |
title="Image Denoising with DeepInverse",
|
50 |
)
|