66"""
77
88import numpy as np
9- import pyunlocbox as plx
109from scipy .signal import fftconvolve
1110
11+ import pyunlocbox as plx
12+
1213###############################################################################
1314# Sample data
1415im = np .random .randn (2748 , 3840 )
1516W = np .random .randn (20 , np .prod (im .shape ))
1617U = np .random .randn (np .prod (im .shape ), 20 )
1718
19+
1820# Setup Forward and Adjoint Models and Create Solver
1921def forward (im ):
2022 im_sim = np .zeros_like (im )
2123 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' )
24+ weight = W [i , :].reshape (* im .shape )
25+ psf_mode = U [:, i ].reshape (* im .shape )
26+ im_sim += fftconvolve (im * weight , psf_mode , mode = " same" )
2527 return im_sim
2628
29+
2730def forward_adj (im ):
2831 im_sim = np .zeros_like (im )
2932 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+ weight = W [i , :].reshape (* im .shape )
34+ psf_mode = U [:, i ].reshape (* im .shape )
35+ im_sim += fftconvolve (im , np .flipud (np .fliplr (psf_mode )), mode = " same" ) * weight
3336 return im_sim
3437
35- tau = 10
38+
39+ tau = 10
3640f1 = plx .functions .norm_l2 (y = im , A = forward , At = forward_adj , lambda_ = tau )
3741f2 = 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' )
42+ solver = plx .solvers .forward_backward (step = 0.5 / tau , accel = plx .acceleration .fista ())
43+ ret = plx .solvers .solve (
44+ [f1 , f2 ], x0 = im .copy (), solver = solver , maxit = 10 , verbosity = "ALL"
45+ )
0 commit comments