def register_astra_geometry(proj_fix, proj_mov, geom_fix, geom_mov, subsamp=1): """ Compute a rigid transformation that makes sure that two reconstruction volumes are alligned. Args: proj_fix : projection data of the fixed volume proj_mov : projection data of the fixed volume geom_fix : projection data of the fixed volume geom_mov : projection data of the fixed volume Returns: geom : geometry for the second reconstruction volume """ print('Computing a rigid tranformation between two datasets.') # Find maximum vol size: sz = numpy.array([proj_fix.shape, proj_mov.shape]).max(0) sz += 10 # for safety... vol1 = numpy.zeros(sz, dtype='float32') vol2 = numpy.zeros(sz, dtype='float32') projector.settings.bounds = [0, 10] projector.settings.subsets = 10 projector.settings['mode'] = 'sequential' projector.FDK(proj_fix, vol1, geom_fix) projector.SIRT(proj_fix, vol1, geom_fix, iterations=5) projector.FDK(proj_mov, vol2, geom_mov) projector.SIRT(proj_mov, vol2, geom_mov, iterations=5) display.slice(vol1, title='Fixed volume preview') display.slice(vol1, title='Moving volume preview') # Find transformation between two volumes: R, T = register_volumes(vol1, vol2, subsamp=subsamp, use_moments=True, use_CG=True) return R, T
flat = data.read_stack(path, 'io00', sample=binn) proj = data.read_stack(path, 'scan_', sample=binn, skip=binn) geom = data.read_flexraylog(path, sample=binn) #%% Prepro: flat = (flat - dark).mean(1) proj = (proj - dark) / flat[:, None, :] proj = -numpy.log(proj).astype('float32') display.slice(proj, dim=1, title='Projection') #%% FDK Recon vol = projector.init_volume(proj) projector.FDK(proj, vol, geom) display.slice(vol, bounds=[], title='FDK') #%% SIRT with additional options vol = projector.init_volume(proj) projector.settings.bounds = [0, 10] projector.settings.subsets = 10 projector.settings.sorting = 'equidistant' projector.SIRT(proj, vol, geom, iterations=5) display.slice(vol, title='SIRT')
projector.backproject(proj, vol_rec, geom) display.slice(vol_rec, title = 'Backprojection') #%% Filtered back-project # Make volume: vol_rec = numpy.zeros_like(vol) # Use FDK: projector.FDK(proj, vol_rec, geom) display.slice(vol_rec, title = 'FDK') #%% Simple SIRT: vol_rec = numpy.zeros_like(vol) projector.SIRT(proj, vol_rec, geom, iterations = 20) display.slice(vol_rec, title = 'SIRT') #%% SIRT with subsets and non-negativity: # Settings: projector.settings.update_residual = True projector.settings.bounds = [0, 2] projector.settings.subsets = 10 projector.settings.sorting = 'equidistant' # Reonstruction: vol_rec = numpy.zeros_like(vol) projector.SIRT(proj, vol_rec, geom, iterations = 20) display.slice(vol_rec, title = 'SIRT')
proj_a = numpy.zeros([128, 32, 128], dtype = 'float32') proj_b = numpy.zeros([128, 32, 128], dtype = 'float32') # Define a simple projection geometry: geom_a = geometry.circular(src2obj = 100, det2obj = 100, det_pixel = 0.01, ang_range = [0, 360]) geom_b = geom_a.copy() geom_b['axs_roll'] = 90 # Create phantom and project into proj: vol = phantom.random_spheroids([128, 128, 128], geom_a, number = 10) display.slice(vol, title = 'Phantom') # Forward project: projector.forwardproject(proj_a, vol, geom_a) projector.forwardproject(proj_b, vol, geom_b) display.slice(proj_a, dim = 1, title = 'Proj A') display.slice(proj_b, dim = 1, title = 'Proj B') #%% Single-dataset SIRT: vol_rec = numpy.zeros_like(vol) projector.SIRT(proj_a, vol_rec, geom_a, iterations = 20) display.slice(vol_rec, bounds = [0, 1], title = 'SIRT') #%% Multi-dataset SIRT: vol_rec = numpy.zeros_like(vol) projector.SIRT([proj_a, proj_b], vol_rec, [geom_a, geom_b], iterations = 20) display.slice(vol_rec, bounds = [0, 1], title = 'Multi-data SIRT')