Skip to content

Commit 7cb5b9c

Browse files
shnaqviSalman Naqvinperraud
authored
Added a new script for testing the spatially varying PSF deconvolution algorithm from Flicker & Rigaugt 2005 (#46)
Co-authored-by: Salman Naqvi <salman_naqvi@apple.com> Co-authored-by: nperraud <6399466+nperraud@users.noreply.github.com>
1 parent 6c96751 commit 7cb5b9c

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

examples/test_deconv_sv_psf.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
r"""
2+
SV_DECONV
3+
=====
4+
This example implements the saptially varying PSF deconvolution algorithm
5+
based on: Flicker & Rigaut, 2005 https://doi.org/10.1364/JOSAA.22.000504
6+
"""
7+
8+
import numpy as np
9+
import pyunlocbox as plx
10+
from scipy.signal import fftconvolve
11+
12+
###############################################################################
13+
# Sample data
14+
im = np.random.randn(2748, 3840)
15+
W = np.random.randn(20, np.prod(im.shape))
16+
U = np.random.randn(np.prod(im.shape), 20)
17+
18+
# Setup Forward and Adjoint Models and Create Solver
19+
def forward(im):
20+
im_sim = np.zeros_like(im)
21+
for i in range(15):
22+
weight = W[i,:].reshape(*im.shape)
23+
psf_mode = U[:,i].reshape(*im.shape)
24+
im_sim += fftconvolve(im* weight, psf_mode, mode='same')
25+
return im_sim
26+
27+
def forward_adj(im):
28+
im_sim = np.zeros_like(im)
29+
for i in range(15):
30+
weight = W[i,:].reshape(*im.shape)
31+
psf_mode = U[:,i].reshape(*im.shape)
32+
im_sim += fftconvolve(im, np.flipud(np.fliplr(psf_mode)), mode='same')* weight
33+
return im_sim
34+
35+
tau=10
36+
f1 = plx.functions.norm_l2(y=im, A=forward, At=forward_adj, lambda_=tau)
37+
f2 = plx.functions.norm_tv(maxit=50, dim=2)
38+
solver = plx.solvers.forward_backward(step=0.5/tau, accel=plx.acceleration.fista())
39+
ret = plx.solvers.solve([f1, f2], x0=im.copy(), solver=solver, maxit=10, verbosity='ALL')

0 commit comments

Comments
 (0)