-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTV_reco_skullCT_2D.py
executable file
·79 lines (57 loc) · 2.29 KB
/
TV_reco_skullCT_2D.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""
TV reconstruction example for simulated Skull CT data - 2D
Note: So far only works for phantom_number = '70100644'
"""
import odl
import numpy as np
import os
import adutils
# Discretization
reco_space = adutils.get_discretization(use_2D=True)
# Forward operator (in the form of a broadcast operator)
A = adutils.get_ray_trafo(reco_space, use_2D=True)
# Data
rhs = adutils.get_data(A, use_2D=True)
# Gradient operator
gradient = odl.Gradient(reco_space, method='forward')
# Column vector of operators
op = odl.BroadcastOperator(A, gradient)
Anorm = odl.power_method_opnorm(A, maxiter=2)
Dnorm = odl.power_method_opnorm(gradient,
xstart=odl.phantom.white_noise(gradient.domain),
maxiter=10)
# Estimated operator norm, add 10 percent
op_norm = 1.1 * np.sqrt(Anorm**2 + Dnorm**2)
print('Norm of the product space operator: {}'.format(op_norm))
lamb = 0.001 # l2NormGrad/l1NormGrad = 0.01
# l2-squared data matching
l2_norm = odl.solvers.L2NormSquared(A.range).translated(rhs)
# Isotropic TV-regularization i.e. the l1-norm
l1_norm = lamb * odl.solvers.L1Norm(gradient.range)
# Combine functionals
f = odl.solvers.SeparableSum(l2_norm, l1_norm)
# Set g functional to zero
g = odl.solvers.ZeroFunctional(op.domain)
# Accelerataion parameter
gamma = 0.5
# Step size for the proximal operator for the primal variable x
tau = 1.0 / op_norm
# Step size for the proximal operator for the dual variable y
sigma = 1.0 / op_norm # 1.0 / (op_norm ** 2 * tau)
# Reconstruct
callbackShowReco = (odl.solvers.CallbackPrintIteration() & # Print iterations
odl.solvers.CallbackShow(clim=[0.018, 0.022]))
callbackPrintIter = odl.solvers.CallbackPrintIteration()
# Use initial guess
x = adutils.get_initial_guess(reco_space)
x = A.domain.zero()
# Run such that last iteration is saved (saveReco = 1) or none (saveReco = 0)
saveReco = False
savePath = '/home/user/Simulated/120kV/'
niter = 400
odl.solvers.chambolle_pock_solver(x, f, g, op, tau=tau, sigma = sigma,
niter = niter, gamma=gamma, callback=callbackShowReco)
if saveReco:
saveName = os.path.join(savePath,'reco/Reco_HelicalSkullCT_70100644Phantom_no_bed_Dose150mGy_TV_' +
str(niter) + 'iterations.npy')
adutils.save_image(x, saveName)