plt.show() # Projection geometry related parameters: Horiz_det = int(np.sqrt(2) * N_size) # detector column count (horizontal) Vert_det = N_size # detector row count (vertical) (no reason for it to be > N) angles_num = int(0.5 * np.pi * N_size) # angles number angles = np.linspace(0.0, 179.9, angles_num, dtype='float32') # in degrees angles_rad = angles * (np.pi / 180.0) #%% # initialise TomoRec DIRECT reconstruction class ONCE from tomorec.methodsDIR import RecToolsDIR RectoolsDIR = RecToolsDIR( DetectorsDimH=Horiz_det, # DetectorsDimH # detector dimension (horizontal) DetectorsDimV= Vert_det, # DetectorsDimV # detector dimension (vertical) for 3D case only AnglesVec=angles_rad, # array of angles in radians ObjSize=N_size, # a scalar to define reconstructed object dimensions device='gpu') #%% print("Building 3D analytical projection data with TomoPhantom") projData3D_analyt = TomoP3D.ModelSino(model, N_size, Horiz_det, Vert_det, angles, path_library3D) intens_max = 70 sliceSel = 150 plt.figure() plt.subplot(131) plt.imshow(projData3D_analyt[:, sliceSel, :], vmin=0, vmax=intens_max) plt.title('2D Projection (analytical)') plt.subplot(132)
plt.xlabel('X-detector', fontsize=16) plt.ylabel('Projection angle', fontsize=16) plt.title('Sinogram (X-Y) view', fontsize=19) plt.subplot(133) plt.imshow(projdata_norm[:,:,sliceSel],vmin=0, vmax=intens_max, cmap="PuOr") plt.xlabel('Projection angle', fontsize=16) plt.ylabel('Z-detector', fontsize=16) plt.title('Vertical (Y-Z) view', fontsize=19) plt.show() #plt.savefig('projdata.pdf', format='pdf', dpi=1200) #%% # initialise TomoRec DIRECT reconstruction class ONCE from tomorec.methodsDIR import RecToolsDIR RectoolsDIR = RecToolsDIR(DetectorsDimH = Horiz_det, # DetectorsDimH # detector dimension (horizontal) DetectorsDimV = Vert_det, # DetectorsDimV # detector dimension (vertical) for 3D case only AnglesVec = proj_angles, # array of angles in radians ObjSize = N_size, # a scalar to define reconstructed object dimensions device = 'gpu') #%% print ("Reconstruction using FBP from TomoRec") recFBP= RectoolsDIR.FBP(projdata_norm) # FBP reconstruction #%% x0, y0 = 0, 127 # These are in _pixel_ coordinates!! x1, y1 = 255, 127 sliceSel = int(0.5*N_size) max_val = 1 plt.figure(figsize = (20,5)) gs1 = gridspec.GridSpec(1, 3) gs1.update(wspace=0.1, hspace=0.05) # set the spacing between axes. ax1 = plt.subplot(gs1[0])
#%% # using normaliser from TomoRec package data_norm = normaliser(data_raw[:, :, 150:160], flats[:, :, 150:160], darks[:, :, 150:160], log='log') # remove nan's data_norm = np.where(np.isfinite(data_norm), data_norm, 0) #%% # Reconstructing normalised data from tomorec.methodsDIR import RecToolsDIR N_size = 1000 detectHoriz, anglesNum, slices = np.shape(data_norm) det_y_crop = [i for i in range(115, detectHoriz)] RectoolsDIR = RecToolsDIR( DetectorsDimH=np.size( det_y_crop), # DetectorsDimH # detector dimension (horizontal) DetectorsDimV= None, # DetectorsDimV # detector dimension (vertical) for 3D case only AnglesVec=angles_rad, # array of angles in radians ObjSize=N_size, # a scalar to define reconstructed object dimensions device='gpu') FBP = RectoolsDIR.FBP(np.transpose(data_norm[det_y_crop, :, 0])) plt.figure() plt.imshow(FBP, vmin=0, vmax=0.003, cmap="gray") plt.title('FBP reconstruction') plt.show()
print("Numerical (ASTRA) sinogram has been generated in {} seconds".format( Run_time)) plt.figure() plt.rcParams.update({'font.size': 21}) plt.imshow(sino_num_ASTRA, cmap="BuPu") plt.colorbar(ticks=[0, 150, 250], orientation='vertical') plt.title('{}' '{}'.format('Numerical sinogram (ASTRA) of model no.', model)) #%% ################################################################### # initialise TomoRec reconstruction class ONCE from tomorec.methodsDIR import RecToolsDIR RectoolsDIR = RecToolsDIR( DetectorsDimH=P, # DetectorsDimH # detector dimension (horizontal) DetectorsDimV= None, # DetectorsDimV # detector dimension (vertical) for 3D case only AnglesVec=angles_rad, # array of angles in radians ObjSize=N_size, # a scalar to define reconstructed object dimensions device='cpu') #%% print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print("Reconstructing analytical sinogram using Fourier Slice method") print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") RecFourier = RectoolsDIR.fourier(sino_an, 'linear') plt.figure() plt.imshow(RecFourier, vmin=0, vmax=1, cmap="BuPu") plt.colorbar(ticks=[0, 0.5, 1], orientation='vertical') plt.title('Fourier slice reconstruction') #%%
ObjSize=N_size, # a scalar to define reconstructed object dimensions datafidelity= 'LS', # data fidelity, choose LS, PWLS (wip), GH (wip), Student (wip) OS_number= None, # the number of subsets, NONE/(or > 1) ~ classical / ordered subsets tolerance=1e-06, # tolerance to stop outer iterations earlier device='gpu') lc = Rectools.powermethod( ) # calculate Lipschitz constant (run once to initilise) from tomorec.methodsDIR import RecToolsDIR RectoolsDIR = RecToolsDIR( DetectorsDimH=P, # DetectorsDimH # detector dimension (horizontal) DetectorsDimV= None, # DetectorsDimV # detector dimension (vertical) for 3D case only AnglesVec=angles_rad, # array of angles in radians ObjSize=N_size, # a scalar to define reconstructed object dimensions device='gpu') FBPrec = RectoolsDIR.FBP(noisy_sino) #perform FBP plt.figure() plt.imshow(FBPrec, vmin=0, vmax=1, cmap="BuPu") plt.colorbar(ticks=[0, 0.5, 1], orientation='vertical') plt.title('FBP reconstruction') #%% print("Pre-calculating weights for non-local patches using FBP image...") pars = {'algorithm' : PatchSelect, \
noisy_zing_stripe = artifacts_add.stripes(percentage=1, maxthickness=1) noisy_zing_stripe[noisy_zing_stripe < 0] = 0 plt.figure() plt.rcParams.update({'font.size': 21}) plt.imshow(noisy_zing_stripe, cmap="gray") plt.colorbar(ticks=[0, 150, 250], orientation='vertical') plt.title('{}' '{}'.format('Analytical noisy sinogram with artifacts.', model)) #%% # initialise TomoRec DIRECT reconstruction class ONCE from tomorec.methodsDIR import RecToolsDIR RectoolsDIR = RecToolsDIR( DetectorsDimH=P, # DetectorsDimH # detector dimension (horizontal) DetectorsDimV= None, # DetectorsDimV # detector dimension (vertical) for 3D case only AnglesVec=angles_rad, # array of angles in radians ObjSize=N_size, # a scalar to define reconstructed object dimensions device='cpu') #%% print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print("Reconstructing analytical sinogram using Fourier Slice method") print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") RecFourier = RectoolsDIR.fourier(sino_an, 'linear') plt.figure() plt.imshow(RecFourier, vmin=0, vmax=1, cmap="BuPu") plt.colorbar(ticks=[0, 0.5, 1], orientation='vertical') plt.title('Fourier slice reconstruction') #%% print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print("Reconstructing analytical sinogram using FBP (TomoRec)...")
angles_rad = angles*(np.pi/180) P = int(np.sqrt(2)*N_size) #detectors sino = TomoP2D.ModelSinoTemporal(model, N_size, P, angles, path_library2D) plt.figure(2) plt.rcParams.update({'font.size': 21}) plt.title('{}''{}'.format('2D+t sinogram of model no.',model)) for sl in range(0,np.shape(phantom_2Dt)[0]): im = sino[sl,:,:].transpose() plt.imshow(im, vmin=0, vmax=180) plt.pause(.1) plt.draw #%% print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print ("Reconstructing analytical sinogram using FBP (TomoRec)...") print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") # initialise TomoRec reconstruction class ONCE from tomorec.methodsDIR import RecToolsDIR RectoolsDIR = RecToolsDIR(DetectorsDimH = P, # DetectorsDimH # detector dimension (horizontal) DetectorsDimV = None, # DetectorsDimV # detector dimension (vertical) for 3D case only AnglesVec = angles_rad, # array of angles in radians ObjSize = N_size, # a scalar to define reconstructed object dimensions device='cpu') FBPrec = RectoolsDIR.FBP(sino[15,:,:].transpose()) # reconstruct one frame plt.figure(3) plt.imshow(FBPrec, vmin=0, vmax=1) plt.title('FBP Reconstructed Phantom') #%%
plt.show() #%% print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print("%%%%%%%%%%%%Reconstructing with FBP method %%%%%%%%%%%%%%%%%") print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") from tomorec.methodsDIR import RecToolsDIR N_size = 950 detectHoriz, anglesNum, timeframe_no = np.shape(data_norm) FBP_timeframes = np.zeros((N_size, N_size, timeframe_no), dtype='float32') for i in range(0, timeframe_no): RectoolsDIR = RecToolsDIR( DetectorsDimH= detectHoriz, # DetectorsDimH # detector dimension (horizontal) DetectorsDimV= None, # DetectorsDimV # detector dimension (vertical) for 3D case only AnglesVec=angles_rad[i, :], # array of angles in radians ObjSize=N_size, # a scalar to define reconstructed object dimensions device='gpu') FBP_timeframes[:, :, i] = RectoolsDIR.FBP(np.transpose(data_norm[:, :, i])) #%% print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print("Reconstructing with FISTA PWLS-OS-TV method % %%%%%%%%%%%%%%") print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") from tomorec.methodsIR import RecToolsIR N_size = 950 detectHoriz, anglesNum, timeframe_no = np.shape(data_norm) FISTA_TV_timeframes = np.zeros((N_size, N_size, timeframe_no), dtype='float32') for i in range(0, timeframe_no):
plt.figure(2) plt.rcParams.update({'font.size': 21}) plt.imshow(sino_an, cmap="BuPu") plt.colorbar(ticks=[0, 150, 250], orientation='vertical') plt.title('{}'.format('Analytical sinogram of an object')) #%% print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print("Reconstructing analytical sinogram using FBP (TomoRec)...") print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") # initialise TomoRec reconstruction class ONCE from tomorec.methodsDIR import RecToolsDIR RectoolsDIR = RecToolsDIR( DetectorsDimH=P, # DetectorsDimH # detector dimension (horizontal) DetectorsDimV= None, # DetectorsDimV # detector dimension (vertical) for 3D case only AnglesVec=angles_rad, # array of angles in radians ObjSize=N_size, # a scalar to define reconstructed object dimensions device='cpu') FBPrec = RectoolsDIR.FBP(sino_an) plt.figure(3) plt.imshow(FBPrec, vmin=0, vmax=1, cmap="BuPu") plt.title('FBP Reconstructed Model') #%% """ Main difference from DemoModel.py is that we extract all parameters from the library file using Python and then pass it to the Object function instead of model. This can be helpful if one would like to avoid using library files and can pass parameters directly into object function