Note
New to DeepInverse? Get started with the basics with the 5 minute quickstart tutorial..
Poisson denoising using Poisson2Sparse#
This code shows how to restore a single image corrupted by Poisson noise using Poisson2Sparse, without requiring external training or knowledge of the noise level.
This method is based on the paper βPoisson2Sparseβ Ta et al.[1] and restores an image by learning a sparse non-linear dictionary parametrized by a neural network using a combination of Neighbor2Neighbor Huang et al.[2], of the negative log Poisson likelihood, of the \(\ell^1\) pixel distance and of a sparsity-inducing \(\ell^1\) regularization function on the weights.
import deepinv as dinv
import torch
Load a Poisson corrupted image#
This example uses an image from the microscopy dataset FMD Zhang et al.[3].
# Seed the RNGs for reproducibility
torch.manual_seed(0)
torch.cuda.manual_seed(0)
device = dinv.utils.get_freer_gpu() if torch.cuda.is_available() else "cpu"
physics = dinv.physics.Denoising(dinv.physics.PoissonNoise(gain=0.01, normalize=True))
x = dinv.utils.demo.load_example(
"FMD_TwoPhoton_MICE_R_gt_12_avg50.png", img_size=(256, 256)
).to(device)
x = x[:, 0:1, :64, :64]
x = x.clamp(0, 1)
y = physics(x)
Selected GPU 0 with 5152.625 MiB free memory
Define the Poisson2Sparse model
backbone = dinv.models.ConvLista(
in_channels=1,
out_channels=1,
kernel_size=3,
num_filters=512,
num_iter=10,
stride=2,
threshold=0.01,
)
model = dinv.models.Poisson2Sparse(
backbone=backbone,
lr=1e-4,
num_iter=200,
weight_n2n=2.0,
weight_l1_regularization=1e-5,
verbose=True,
).to(device)
Run the model#
Note that we do not pass in the physics model as Poisson2Sparse assumes a Poisson noise model internally and does not depend on the noise level.
x_hat = model(y)
# Compute and display PSNR values
learning_free_psnr = dinv.metric.PSNR()(y, x).item()
model_psnr = dinv.metric.PSNR()(x_hat, x).item()
print(f"Measurement PSNR: {learning_free_psnr:.1f} dB")
print(f"Poisson2Sparse PSNR: {model_psnr:.1f} dB")
# Plot results
dinv.utils.plot(
[y, x_hat, x],
titles=["Measurement", "Poisson2Sparse", "Ground truth"],
subtitles=[f"{learning_free_psnr:.1f} dB", f"{model_psnr:.1f} dB", ""],
)

0%| | 0/200 [00:00<?, ?it/s]
4%|β | 7/200 [00:00<00:02, 68.79it/s]
8%|β | 16/200 [00:00<00:02, 78.54it/s]
12%|ββ | 24/200 [00:00<00:02, 59.65it/s]
16%|ββ | 31/200 [00:00<00:03, 47.42it/s]
18%|ββ | 37/200 [00:00<00:03, 42.89it/s]
21%|ββ | 42/200 [00:00<00:03, 40.89it/s]
24%|βββ | 47/200 [00:01<00:03, 38.95it/s]
26%|βββ | 52/200 [00:01<00:03, 38.01it/s]
28%|βββ | 56/200 [00:01<00:03, 37.27it/s]
30%|βββ | 60/200 [00:01<00:03, 36.85it/s]
32%|ββββ | 64/200 [00:01<00:03, 36.61it/s]
34%|ββββ | 68/200 [00:01<00:03, 36.28it/s]
36%|ββββ | 72/200 [00:01<00:03, 35.72it/s]
38%|ββββ | 76/200 [00:01<00:03, 35.71it/s]
40%|ββββ | 80/200 [00:01<00:03, 35.98it/s]
42%|βββββ | 84/200 [00:02<00:03, 35.90it/s]
44%|βββββ | 88/200 [00:02<00:03, 35.71it/s]
46%|βββββ | 92/200 [00:02<00:03, 35.65it/s]
48%|βββββ | 96/200 [00:02<00:02, 35.27it/s]
50%|βββββ | 100/200 [00:02<00:02, 35.96it/s]
52%|ββββββ | 104/200 [00:02<00:02, 35.98it/s]
54%|ββββββ | 108/200 [00:02<00:02, 35.42it/s]
56%|ββββββ | 112/200 [00:02<00:02, 35.49it/s]
58%|ββββββ | 116/200 [00:02<00:02, 35.15it/s]
60%|ββββββ | 120/200 [00:03<00:02, 35.34it/s]
62%|βββββββ | 124/200 [00:03<00:02, 35.51it/s]
64%|βββββββ | 128/200 [00:03<00:01, 36.08it/s]
66%|βββββββ | 132/200 [00:03<00:01, 35.72it/s]
68%|βββββββ | 136/200 [00:03<00:01, 35.72it/s]
70%|βββββββ | 140/200 [00:03<00:01, 35.64it/s]
72%|ββββββββ | 144/200 [00:03<00:01, 35.54it/s]
74%|ββββββββ | 148/200 [00:03<00:01, 35.15it/s]
76%|ββββββββ | 152/200 [00:03<00:01, 35.24it/s]
78%|ββββββββ | 156/200 [00:04<00:01, 35.12it/s]
80%|ββββββββ | 160/200 [00:04<00:01, 35.52it/s]
82%|βββββββββ | 164/200 [00:04<00:01, 35.01it/s]
84%|βββββββββ | 168/200 [00:04<00:00, 35.27it/s]
86%|βββββββββ | 172/200 [00:04<00:00, 35.61it/s]
88%|βββββββββ | 176/200 [00:04<00:00, 35.60it/s]
90%|βββββββββ | 180/200 [00:04<00:00, 35.40it/s]
92%|ββββββββββ| 184/200 [00:04<00:00, 35.59it/s]
94%|ββββββββββ| 188/200 [00:05<00:00, 35.92it/s]
96%|ββββββββββ| 192/200 [00:05<00:00, 35.49it/s]
98%|ββββββββββ| 196/200 [00:05<00:00, 35.51it/s]
100%|ββββββββββ| 200/200 [00:05<00:00, 35.44it/s]
100%|ββββββββββ| 200/200 [00:05<00:00, 37.43it/s]
Measurement PSNR: 27.5 dB
Poisson2Sparse PSNR: 31.1 dB
- References:
Total running time of the script: (0 minutes 5.668 seconds)