Example #1
0
"""

import numpy as np
import adutils

# Discretization
reco_space = adutils.get_discretization()

# Forward operator (in the form of a broadcast operator)
A = adutils.get_ray_trafo(reco_space, use_subset=True)

# Define fbp
fbp = adutils.get_fbp(A)

# Data
rhs = adutils.get_data(A, use_subset=True)

# Reconstruct
x = fbp(rhs)

# Show result
x.show(coords=[None, 0, None])
x.show(coords=[0, None, None])
x.show(coords=[None, None, 90])

# Save
saveReco = False
if saveReco:
    saveName = '/home/user/Simulated/120kV/reco/Reco_HelicalSkullCT_70100644Phantom_no_bed_Dose150mGy_FBP.npy'
    adutils.save_image(x, saveName)
Example #2
0
"""
TGV reconstruction example for simulated Skull CT data
"""

import odl
import numpy as np
import adutils

# Discretization
reco_space = adutils.get_discretization(use_2D=True)

# Forward operator (in the form of a broadcast operator)
ray_trafo = adutils.get_ray_trafo(reco_space, use_2D=True)

# Data
data = adutils.get_data(ray_trafo, use_2D=True)


# --- Set up the inverse problem --- #


# Initialize gradient operator
gradient = odl.Gradient(reco_space, method='forward')

gradient_back = odl.Gradient(reco_space, method='backward')
eps = odl.DiagonalOperator(gradient_back, reco_space.ndim)

# Create the domain of the problem, given by the reconstruction space and the
# range of the gradient on the reconstruction space.
domain = odl.ProductSpace(reco_space, gradient.range)
Example #3
0
# Discretization
reco_space = adutils.get_discretization(phantom_number=phantom_number)

# Forward operator (in the form of a broadcast operator)
A = adutils.get_ray_trafo(reco_space,
                          phantom_number=phantom_number,
                          use_rebin=True,
                          rebin_factor=rebin_factor)

# Define fbp
fbp = adutils.get_fbp(A)

# Data
rhs = adutils.get_data(A,
                       phantom_number=phantom_number,
                       use_rebin=True,
                       rebin_factor=rebin_factor)

# Reconstruct
x = fbp(rhs)

# Show result
x.show(coords=[None, 0, None])
x.show(coords=[0, None, None])
x.show(coords=[None, None, 90])

# Save
saveReco = False
if saveReco:
    saveName = '/home/user/FBP_reco_rebinned.npy'
    adutils.save_image(x, saveName)
"""

import numpy as np
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)

# Define fbp
fbp = adutils.get_fbp(A, use_2D=True)

# Data
rhs = adutils.get_data(A, use_2D=True)

# Reconstruct
x = fbp(rhs)

# Show result
x.show()

# Compare to phantom
phantom = reco_space.element(adutils.get_phantom(use_2D=True))

phantom.show()

# Save
saveReco = False
if saveReco:
import numpy as np
import os
import adutils

# Define phantom name (or use default '70100644')
phantom_number = '70100644'

# Discretization
reco_space = adutils.get_discretization(phantom_number=phantom_number)

# Forward operator (in the form of a broadcast operator)
A = adutils.get_ray_trafo(reco_space,
                          phantom_number=phantom_number)

# Data
rhs = adutils.get_data(A,
                       phantom_number=phantom_number)

# Gradient operator
gradient = odl.Gradient(reco_space, method='forward')

# Column vector of operators
op = odl.BroadcastOperator(A, gradient)

Anorm = odl.power_method_opnorm(A[1], 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(len(A.operators)*(Anorm**2) + Dnorm**2)
"""
TV reconstruction example for simulated Skull CT data - lambda parameter search
"""
import odl
import numpy as np
import os
import adutils

# Discretization
reco_space = adutils.get_discretization()

# Forward operator (in the form of a broadcast operator)
A = adutils.get_ray_trafo(reco_space)

# Data
rhs = adutils.get_data(A)

# Gradient operator
gradient = odl.Gradient(reco_space, method='forward')

# Column vector of operators
op = odl.BroadcastOperator(A, gradient)

Anorm = odl.power_method_opnorm(A[1], 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(len(A.operators)*(Anorm**2) + Dnorm**2)
# Define phantom name (or use default '70100644')
phantom_number = '70100644'

# Discretization
reco_space = adutils.get_discretization(phantom_number=phantom_number)

# Forward operator (in the form of a broadcast operator)
A = adutils.get_ray_trafo(reco_space,
                          use_subset=True,
                          phantom_number=phantom_number)

# Define fbp
fbp = adutils.get_fbp(A)

# Data
rhs = adutils.get_data(A, use_subset=True, phantom_number=phantom_number)

# Reconstruct
x = fbp(rhs)

# Show result
x.show(coords=[None, 0, None])
x.show(coords=[0, None, None])
x.show(coords=[None, None, 90])

# Save
saveReco = False
if saveReco:
    saveName = '/home/user/FBP_reco.npy'
    adutils.save_image(x, saveName)
Example #8
0
"""
Wavelet reconstruction example for simulated Skull CT data - parameter search
"""
import odl
import numpy as np
import adutils

# Discretization
reco_space = adutils.get_discretization()

# Forward operator (in the form of a broadcast operator)
A = adutils.get_ray_trafo(reco_space, use_rebin=True)

# Data
rhs = adutils.get_data(A, use_rebin=True)

# Use FBP as initial guess
x_init = adutils.get_initial_guess(reco_space)

for wavelet in ['db1', 'db2']:

    # Create wavelet operator
    W = odl.trafos.WaveletTransform(reco_space, wavelet=wavelet, nlevels=5)

    # The wavelets bases are normalized to constant norm regardless of scale.
    # since we want to penalize "small" wavelets more than "large" ones, we need
    # to weight by the scale of the wavelets.
    # The "area" of the wavelets scales as 3 ^ scale, but we use a slightly smaller
    # number in order to allow some high frequencies.
    scales = W.scales()
Example #9
0
import numpy as np
import os
import adutils

rebin_factor = 10

# Discretization
reco_space = adutils.get_discretization()

# Forward operator (in the form of a broadcast operator)
A = adutils.get_ray_trafo(reco_space,
                          use_rebin=True,
                          rebin_factor=rebin_factor)

# Data
rhs = adutils.get_data(A, use_rebin=True, rebin_factor=rebin_factor)

# Reconstruct
callbackShowReco = (odl.solvers.CallbackPrintIteration()
                    & odl.solvers.CallbackShow(coords=[None, 0, None])
                    & odl.solvers.CallbackShow(coords=[0, None, None])
                    & odl.solvers.CallbackShow(coords=[None, None, 60]))

callbackPrintIter = odl.solvers.CallbackPrintIteration()

title = 'my reco'
lamb = 0.01
pth = '/home/davlars/ad-skull-reconstruction/data/results/tv/lambda_{}'.format(
    float(lamb)) + '_iterate_{}.png'

# Reconstruct