def CT(load_path, dset, sc, ang_freq, Exp_bin, bin_param, nTrain, nTD, nVal, nVD, bpath): dataset = ddf.load_and_preprocess_real_data(load_path, dset, sc) meta = ddf.load_meta(load_path + dset + '/', sc) pix_size = meta['pix_size'] src_rad = meta['s2o'] det_rad = meta['o2d'] data_obj = ddf.real_data(dataset, pix_size, src_rad, det_rad, ang_freq, zoom=False) CT_obj = ddf.CCB_CT(data_obj) CT_obj.init_algo() spf_space, Exp_op = ddf.support_functions.ExpOp_builder( bin_param, CT_obj.filter_space, interp=Exp_bin) # Create the FDK binned operator # CT_obj.FDK_bin_nn = CT_obj.FDK_op * Exp_op # Create the NN-FDK object CT_obj.NNFDK = nn.NNFDK_class(CT_obj, nTrain, nTD, nVal, nVD, Exp_bin, Exp_op, bin_param, dset=dset, base_path=bpath) CT_obj.rec_methods += [CT_obj.NNFDK] return CT_obj
def CT(load_path, dset, sc, ang_freq): dataset = ddf.load_and_preprocess_real_data(load_path, dset, sc) meta = ddf.load_meta(load_path + dset + '/', sc) pix_size = meta['pix_size'] src_rad = meta['s2o'] det_rad = meta['o2d'] data_obj = ddf.real_data(dataset, pix_size, src_rad, det_rad, ang_freq, zoom=False) CT_obj = ddf.CCB_CT(data_obj) CT_obj.init_algo() return CT_obj
def CT(path, dset, sc, ang_freq, vox): dataset, vecs = cap.load_and_preprocess(path, dset, ang_freq=ang_freq) meta = ddf.load_meta(f'{path}{dset}/', 1) pix_size = sc * meta['pix_size'] src_rad = meta['s2o'] det_rad = meta['o2d'] data_obj = ddf.real_data(dataset, pix_size, src_rad, det_rad, ang_freq, vox=vox, vecs=vecs) CT_obj = ddf.CCB_CT(data_obj) CT_obj.init_algo() return CT_obj
def CT(load_path, dset, sc, ang_freq, Exp_bin, bin_param, offset): dataset = ddf.load_and_preprocess_real_data(load_path, dset, sc) meta = ddf.load_meta(load_path + dset + '/', sc) pix_size = meta['pix_size'] src_rad = meta['s2o'] det_rad = meta['o2d'] data_obj = ddf.real_data(dataset, pix_size, src_rad, det_rad, ang_freq, zoom=True, offset=offset) CT_obj = ddf.CCB_CT(data_obj) CT_obj.init_algo() CT_obj.init_DDF_FDK() return CT_obj
def CT(path, dset, sc, ang_freq, Exp_bin, bin_param, nTrain, nTD, nVal, nVD, vox, bp): dataset, vecs = cap.load_and_preprocess(path, dset, ang_freq=ang_freq) meta = ddf.load_meta(f'{path}{dset}/', 1) pix_size = sc * meta['pix_size'] src_rad = meta['s2o'] det_rad = meta['o2d'] data_obj = ddf.real_data(dataset, pix_size, src_rad, det_rad, ang_freq, vox=vox, vecs=vecs) CT_obj = ddf.CCB_CT(data_obj) CT_obj.init_algo() spf_space, Exp_op = ddf.support_functions.ExpOp_builder( bin_param, CT_obj.filter_space, interp=Exp_bin) # Create the FDK binned operator # CT_obj.FDK_bin_nn = CT_obj.FDK_op * Exp_op # Create the NN-FDK object CT_obj.NNFDK = nn.NNFDK_class(CT_obj, nTrain, nTD, nVal, nVD, Exp_bin, Exp_op, bin_param, dset=dset, base_path=bp) CT_obj.rec_methods += [CT_obj.NNFDK] return CT_obj
src_rad = meta['s2o'] det_rad = meta['o2d'] #dataset = {'g': } # Specifics for the expansion operator Exp_bin = 'linear' bin_param = 2 # %% Create a test phantom # Create a data object t2 = time.time() offset = 1.26 / 360 * 2 * np.pi data_obj = ddf.real_data(dataset, pix_size, src_rad, det_rad, ang_freq, zoom=True, offset=offset) print('Making phantom and mask took', time.time() - t2, 'seconds') # The amount of projection angles in the measurements # Source to center of rotation radius t3 = time.time() # %% Create the circular cone beam CT class case = ddf.CCB_CT(data_obj) #, angles, src_rad, det_rad, noise) print('Making data and operators took', time.time() - t3, 'seconds') # Initialize the algorithms (FDK, SIRT) t4 = time.time() case.init_algo()
dataset = {'g': f'{bpath}g_noisy.npy', 'ground_truth' : f'{bpath}ground_truth.npy', 'mask': f'{bpath}mask.npy'} # I found this details by myself in .txt file which came with dataset # This is correct, but my code assumes cm's and these are mm's --> /10 pix_size = 0.149600 / 10 * sc # These were incorrect. Fixed now: src_rad = 46.3 det_rad = 37.6 # We do not have to defien the vox here, this will be automatically 768 // sc data_obj = ddf.real_data(dataset, pix_size, src_rad, det_rad, ang_freq, zoom=False) case = ddf.CCB_CT(data_obj) case.init_algo() # %% Create NN-FDK algorithm setup # Create binned filter space and expansion operator spf_space, Exp_op = ddf.support_functions.ExpOp_builder(bin_param, case.filter_space, interp=Exp_bin) # Create the FDK binned operator #case.FDK_bin_nn = case.FDK_op * Exp_op # Create the NN-FDK object
def Create_dataset_ASTRA_real(dataset, pix_size, src_rad, det_rad, ang_freq, Exp_bin, bin_param, vox=None, vecs=None): # ! ! ! We overide 'vox' and 'vecs' later on # The size of the measured objects in voxels data_obj = ddf.real_data(dataset, pix_size, src_rad, det_rad, ang_freq, vox=vox, vecs=vecs) g = np.ascontiguousarray(np.transpose(np.asarray(data_obj.g.copy()), (2, 0, 1)), dtype=np.float32) v, ang, u = g.shape if vox is None: voxels = data_obj.voxels else: voxels = [vox, vox, vox] MaxVoxDataset = np.max([int(voxels[0]**3 * 0.005), 5 * 10**6]) Smat = Make_Smat(voxels, MaxVoxDataset, '', real_data=dataset['mask']) # %% Create geometry geom = data_obj.geometry w_du = data_obj.pix_size dpix = [u, v] minvox = data_obj.reco_space.min_pt[0] maxvox = data_obj.reco_space.max_pt[0] vox = np.shape(data_obj.reco_space)[0] vol_geom = astra.create_vol_geom(vox, vox, vox, minvox, maxvox, minvox, maxvox, minvox, maxvox) # Build a vecs vector from the geometry, or load it if type(geom) == np.ndarray: vecs = geom proj_geom = astra.create_proj_geom('cone_vec', v, u, vecs) elif type(geom) == odl.tomo.geometry.conebeam.ConeFlatGeometry: angles = np.linspace((1 / ang) * np.pi, (2 + 1 / ang) * np.pi, ang, False) w_du, w_dv = 2 * data_obj.geometry.detector.partition.max_pt / [u, v] proj_geom = astra.create_proj_geom('cone', w_dv, w_du, v, u, angles, data_obj.geometry.src_radius, data_obj.geometry.det_radius) filter_part = odl.uniform_partition(-data_obj.detecsize[0], data_obj.detecsize[0], dpix[0]) filter_space = odl.uniform_discr_frompartition(filter_part, dtype='float64') spf_space, Exp_op = ddf.ExpOp_builder(bin_param, filter_space, interp=Exp_bin) nParam = np.size(spf_space) fullFilterSize = int(2**(np.ceil(np.log2(dpix[0])) + 1)) halfFilterSize = fullFilterSize // 2 + 1 Resize_Op = odl.ResizingOperator(Exp_op.range, ran_shp=(fullFilterSize, )) # %% Create projection and reconstion objects proj_id = astra.data3d.link('-proj3d', proj_geom, g) rec = np.zeros(astra.geom_size(vol_geom), dtype=np.float32) rec_id = astra.data3d.link('-vol', vol_geom, rec) B = np.zeros((MaxVoxDataset, nParam + 1)) # %% Make the matrix columns of the matrix B for nP in range(nParam): unit_vec = spf_space.zero() unit_vec[nP] = 1 filt = Exp_op(unit_vec) rs_filt = Resize_Op(filt) f_filt = np.real(np.fft.rfft(np.fft.ifftshift(rs_filt))) filter2d = np.zeros((ang, halfFilterSize)) for i in range(ang): filter2d[i, :] = f_filt * 4 * w_du # %% Make a filter geometry filter_geom = astra.create_proj_geom('parallel', w_du, halfFilterSize, np.zeros(ang)) filter_id = astra.data2d.create('-sino', filter_geom, filter2d) # cfg = astra.astra_dict('FDK_CUDA') cfg['ReconstructionDataId'] = rec_id cfg['ProjectionDataId'] = proj_id cfg['option'] = {'FilterSinogramId': filter_id} # Create the algorithm object from the configuration structure alg_id = astra.algorithm.create(cfg) # %% astra.algorithm.run(alg_id) rec = np.transpose(rec, (2, 1, 0)) B[:, nP] = rec[Smat] # %% # Clean up. Note that GPU memory is tied up in the algorithm object, # and main RAM in the data objects. B[:, -1] = data_obj.f[Smat] astra.algorithm.delete(alg_id) astra.data3d.delete(rec_id) astra.data3d.delete(proj_id) return B