Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a new test script for deconvolution #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions examples/test_deconv_sv_psf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
r"""
SV_DECONV
=====
This example implements the saptially varying PSF deconvolution algorithm
based on: Flicker & Rigaut, 2005 https://doi.org/10.1364/JOSAA.22.000504
"""

import numpy as np
import pyunlocbox as plx
from scipy.signal import fftconvolve

###############################################################################
# Sample data
im = np.random.randn(2748, 3840)
W = np.random.randn(20, np.prod(im.shape))
U = np.random.randn(np.prod(im.shape), 20)

# Setup Forward and Adjoint Models and Create Solver
def forward(im):
im_sim = np.zeros_like(im)
for i in range(15):
weight = W[i,:].reshape(*im.shape)
psf_mode = U[:,i].reshape(*im.shape)
im_sim += fftconvolve(im* weight, psf_mode, mode='same')
return im_sim

def forward_adj(im):
im_sim = np.zeros_like(im)
for i in range(15):
weight = W[i,:].reshape(*im.shape)
psf_mode = U[:,i].reshape(*im.shape)
im_sim += fftconvolve(im, np.flipud(np.fliplr(psf_mode)), mode='same')* weight
return im_sim

tau=10
f1 = plx.functions.norm_l2(y=im, A=forward, At=forward_adj, lambda_=tau)
f2 = plx.functions.norm_tv(maxit=50, dim=2)
solver = plx.solvers.forward_backward(step=0.5/tau, accel=plx.acceleration.fista())
ret = plx.solvers.solve([f1, f2], x0=im.copy(), solver=solver, maxit=10, verbosity='ALL')