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