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:
# 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()
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')
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}