Exemplo n.º 1
0
plt.imshow(b.array)
plt.title('Simulated data')
plt.show()

plt.imshow(z.array)
plt.title('Backprojected data')
plt.show()

# Using the test data b, different reconstruction methods can now be set up as
# demonstrated in the rest of this file. In general all methods need an initial
# guess and some algorithm options to be set:
x_init = ImageData(np.zeros(x.shape), geometry=ig)
opt = {'tol': 1e-4, 'iter': 1000}

# First a CGLS reconstruction can be done:
x_CGLS, it_CGLS, timing_CGLS, criter_CGLS = CGLS(x_init, Aop, b, opt)

plt.imshow(x_CGLS.array)
plt.title('CGLS')
plt.colorbar()
plt.show()

plt.semilogy(criter_CGLS)
plt.title('CGLS criterion')
plt.show()

# A SIRT unconstrained reconstruction can be done: similarly:
x_SIRT, it_SIRT, timing_SIRT, criter_SIRT = SIRT(x_init, Aop, b, opt)

plt.imshow(x_SIRT.array)
plt.title('SIRT unconstrained')
Exemplo n.º 2
0
plt.imshow(b.array)
plt.title('Simulated data')
plt.show()

plt.imshow(z.array)
plt.title('Backprojected data')
plt.show()

# Using the test data b, different reconstruction methods can now be set up as
# demonstrated in the rest of this file. In general all methods need an initial
# guess and some algorithm options to be set:
x_init = ImageData(np.zeros(x.shape), geometry=ig)
opt = {'tol': 1e-4, 'iter': 1000}

# First a CGLS reconstruction can be done:
x_CGLS, it_CGLS, timing_CGLS, criter_CGLS = CGLS(x_init, Aop, b, opt)

plt.imshow(x_CGLS.array)
plt.title('CGLS')
plt.show()

plt.semilogy(criter_CGLS)
plt.title('CGLS criterion')
plt.show()

# CGLS solves the simple least-squares problem. The same problem can be solved
# by FISTA by setting up explicitly a least squares function object and using
# no regularisation:

# Create least squares object instance with projector, test data and a constant
# coefficient of 0.5:
Exemplo n.º 3
0
print("Run FBPD for least squares plus 1-norm regularisation")
x_fbpd1, it_fbpd1, timing_fbpd1, criter_fbpd1 = FBPD(x_init,
                                                     None,
                                                     f,
                                                     g0,
                                                     opt=opt)

plt.imshow(x_fbpd1.subset(horizontal_x=80).array)
plt.title('FBPD LS+1')
plt.colorbar()
plt.show()

# Run CGLS, which should agree with the FISTA least squares
print("Run CGLS for least squares")
x_CGLS, it_CGLS, timing_CGLS, criter_CGLS = CGLS(x_init,
                                                 Cop,
                                                 padded_data2,
                                                 opt=opt)
plt.imshow(x_CGLS.subset(horizontal_x=80).array)
plt.title('CGLS')
plt.colorbar()
plt.show()

# Display all reconstructions and decay of objective function
cols = 4
rows = 1
current = 1
fig = plt.figure()

current = current
a = fig.add_subplot(rows, cols, current)
a.set_title('FISTA LS')
Exemplo n.º 4
0
# So and show simple backprojection
z = Aop.adjoint(data2)
plt.figure()
plt.imshow(z.subset(horizontal_x=1000).as_array())
plt.show()
plt.figure()
plt.imshow(z.subset(horizontal_y=1000).as_array())
plt.show()
plt.figure()
plt.imshow(z.subset(vertical=100).array)
plt.show()

# Set initial guess for CGLS reconstruction
x_init = ImageData(geometry=ig)

# Run 50-iteration CGLS reconstruction
opt = {'tol': 1e-4, 'iter': 20}
x, it, timing, criter = CGLS(x_init,Aop,data2,opt=opt)

# Display ortho slices of reconstruction
plt.figure()
plt.imshow(x.subset(horizontal_x=1000).as_array())
plt.show()
plt.figure()
plt.imshow(x.subset(horizontal_y=1000).as_array())
plt.show()
plt.figure()
plt.imshow(x.subset(vertical=100).as_array())
plt.show()
Exemplo n.º 5
0
plt.imshow(z.subset(vertical=0).array)
plt.title('Backprojected data')
plt.show()

# Using the test data b, different reconstruction methods can now be set up as
# demonstrated in the rest of this file. In general all methods need an initial
# guess and some algorithm options to be set. Note that 100 iterations for
# some of the methods is a very low number and 1000 or 10000 iterations may be
# needed if one wants to obtain a converged solution.
x_init = ImageData(
    geometry=ig, dimension_labels=['horizontal_x', 'horizontal_y', 'vertical'])
opt = {'tol': 1e-4, 'iter': 100}

# First a CGLS reconstruction can be done:
x_CGLS, it_CGLS, timing_CGLS, criter_CGLS = CGLS(x_init, Cop, b, opt=opt)

plt.imshow(x_CGLS.subset(vertical=0).array)
plt.title('CGLS')
plt.show()

plt.semilogy(criter_CGLS)
plt.title('CGLS criterion')
plt.show()

# CGLS solves the simple least-squares problem. The same problem can be solved
# by FISTA by setting up explicitly a least squares function object and using
# no regularisation:

# Create least squares object instance with projector, test data and a constant
# coefficient of 0.5:
Exemplo n.º 6
0
Aall = AstraProjectorMC(ig2d, ag2d, 'gpu')

# Compute and simple backprojction and display one channel as image.
Xbp = Aall.adjoint(data2d)
plt.imshow(Xbp.subset(channel=100).array)
plt.show()

# Set initial guess ImageData with zeros for algorithms, and algorithm options.
x_init = ImageData(
    numpy.zeros((num_channels, num_pixels_v, num_pixels_h)),
    geometry=ig2d,
    dimension_labels=['channel', 'horizontal_y', 'horizontal_x'])
opt_CGLS = {'tol': 1e-4, 'iter': 5}

# Run CGLS algorithm and display one channel.
x_CGLS, it_CGLS, timing_CGLS, criter_CGLS = CGLS(x_init, Aall, data2d,
                                                 opt_CGLS)

plt.imshow(x_CGLS.subset(channel=100).array)
plt.title('CGLS')
plt.show()

plt.semilogy(criter_CGLS)
plt.title('CGLS Criterion vs iterations')
plt.show()

# Create least squares object instance with projector, test data and a constant
# coefficient of 0.5. Note it is least squares over all channels.
f = Norm2sq(Aall, data2d, c=0.5)

# Options for FISTA algorithm.
opt = {'tol': 1e-4, 'iter': 100}
Exemplo n.º 7
0
# Choose the number of voxels to reconstruct onto as number of detector pixels
N = data.geometry.pixel_num_h

# Geometric magnification
mag = (np.abs(data.geometry.dist_center_detector) + \
      np.abs(data.geometry.dist_source_center)) / \
      np.abs(data.geometry.dist_source_center)

# Voxel size is detector pixel size divided by mag
voxel_size_h = data.geometry.pixel_size_h / mag

# Construct the appropriate ImageGeometry
ig2d = ImageGeometry(voxel_num_x=N,
                     voxel_num_y=N,
                     voxel_size_x=voxel_size_h,
                     voxel_size_y=voxel_size_h)

# Set up the Projector (AcquisitionModel) using ASTRA on GPU
Aop = AstraProjectorSimple(ig2d, ag2d, "gpu")

# Set initial guess for CGLS reconstruction
x_init = ImageData(np.zeros((N, N)), geometry=ig2d)

# Run 50-iteration CGLS reconstruction
opt = {'tol': 1e-4, 'iter': 50}
x, it, timing, criter = CGLS(x_init, Aop, data2d, opt=opt)

# Display reconstruction
plt.figure()
plt.imshow(x.as_array())
plt.colorbar()