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 3730.25 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", ""],
)
Measurement, Poisson2Sparse, Ground truth
  0%|          | 0/200 [00:00<?, ?it/s]
  1%|          | 2/200 [00:00<00:10, 18.64it/s]
  3%|β–Ž         | 6/200 [00:00<00:07, 26.28it/s]
  5%|β–Œ         | 10/200 [00:00<00:06, 29.35it/s]
  7%|β–‹         | 14/200 [00:00<00:06, 29.89it/s]
  9%|β–‰         | 18/200 [00:00<00:05, 31.09it/s]
 11%|β–ˆ         | 22/200 [00:00<00:05, 31.04it/s]
 13%|β–ˆβ–Ž        | 26/200 [00:00<00:05, 31.43it/s]
 15%|β–ˆβ–Œ        | 30/200 [00:00<00:05, 31.40it/s]
 17%|β–ˆβ–‹        | 34/200 [00:01<00:05, 31.54it/s]
 19%|β–ˆβ–‰        | 38/200 [00:01<00:05, 31.32it/s]
 21%|β–ˆβ–ˆ        | 42/200 [00:01<00:04, 31.79it/s]
 23%|β–ˆβ–ˆβ–Ž       | 46/200 [00:01<00:04, 31.52it/s]
 25%|β–ˆβ–ˆβ–Œ       | 50/200 [00:01<00:04, 31.90it/s]
 27%|β–ˆβ–ˆβ–‹       | 54/200 [00:01<00:04, 31.40it/s]
 29%|β–ˆβ–ˆβ–‰       | 58/200 [00:01<00:04, 31.18it/s]
 31%|β–ˆβ–ˆβ–ˆ       | 62/200 [00:02<00:04, 31.26it/s]
 33%|β–ˆβ–ˆβ–ˆβ–Ž      | 66/200 [00:02<00:04, 31.53it/s]
 35%|β–ˆβ–ˆβ–ˆβ–Œ      | 70/200 [00:02<00:04, 31.68it/s]
 37%|β–ˆβ–ˆβ–ˆβ–‹      | 74/200 [00:02<00:03, 31.63it/s]
 39%|β–ˆβ–ˆβ–ˆβ–‰      | 78/200 [00:02<00:03, 31.89it/s]
 41%|β–ˆβ–ˆβ–ˆβ–ˆ      | 82/200 [00:02<00:03, 31.70it/s]
 43%|β–ˆβ–ˆβ–ˆβ–ˆβ–Ž     | 86/200 [00:02<00:03, 31.80it/s]
 45%|β–ˆβ–ˆβ–ˆβ–ˆβ–Œ     | 90/200 [00:02<00:03, 31.52it/s]
 47%|β–ˆβ–ˆβ–ˆβ–ˆβ–‹     | 94/200 [00:03<00:03, 31.75it/s]
 49%|β–ˆβ–ˆβ–ˆβ–ˆβ–‰     | 98/200 [00:03<00:03, 31.56it/s]
 51%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ     | 102/200 [00:03<00:03, 32.00it/s]
 53%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Ž    | 106/200 [00:03<00:02, 31.77it/s]
 55%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ    | 110/200 [00:03<00:02, 31.80it/s]
 57%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‹    | 114/200 [00:03<00:02, 31.64it/s]
 59%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‰    | 118/200 [00:03<00:02, 31.75it/s]
 61%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ    | 122/200 [00:03<00:02, 31.65it/s]
 63%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Ž   | 126/200 [00:04<00:02, 31.82it/s]
 65%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ   | 130/200 [00:04<00:02, 31.55it/s]
 67%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‹   | 134/200 [00:04<00:02, 31.89it/s]
 69%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‰   | 138/200 [00:04<00:01, 31.49it/s]
 71%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ   | 142/200 [00:04<00:01, 31.15it/s]
 73%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Ž  | 146/200 [00:04<00:01, 30.77it/s]
 75%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ  | 150/200 [00:04<00:01, 30.96it/s]
 77%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‹  | 154/200 [00:04<00:01, 31.02it/s]
 79%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‰  | 158/200 [00:05<00:01, 31.42it/s]
 81%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  | 162/200 [00:05<00:01, 31.42it/s]
 83%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Ž | 166/200 [00:05<00:01, 31.60it/s]
 85%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ | 170/200 [00:05<00:00, 31.51it/s]
 87%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‹ | 174/200 [00:05<00:00, 31.67it/s]
 89%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‰ | 178/200 [00:05<00:00, 31.53it/s]
 91%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ | 182/200 [00:05<00:00, 31.72it/s]
 93%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Ž| 186/200 [00:05<00:00, 31.34it/s]
 95%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ| 190/200 [00:06<00:00, 31.19it/s]
 97%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‹| 194/200 [00:06<00:00, 31.18it/s]
 99%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‰| 198/200 [00:06<00:00, 31.45it/s]
100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 200/200 [00:06<00:00, 31.33it/s]
Measurement PSNR: 27.5 dB
Poisson2Sparse PSNR: 30.3 dB
References:

Total running time of the script: (0 minutes 7.205 seconds)

Gallery generated by Sphinx-Gallery