def calculate_norm(self): igtmp = self.volume_geometry.clone() igtmp.shape = self.volume_geometry.shape[1:] igtmp.dimension_labels = ['horizontal_y', 'horizontal_x'] igtmp.channels = 1 agtmp = self.sinogram_geometry.clone() agtmp.shape = self.sinogram_geometry.shape[1:] agtmp.dimension_labels = ['angle', 'horizontal'] agtmp.channels = 1 Atmp = AstraProjectorSimple(igtmp, agtmp, device=self.device) return Atmp.norm()
N = 150 M = 150 data = loader.load(TestData.SIMPLE_PHANTOM_2D, size=(N, M), scale=(0, 1)) ig = data.geometry detectors = N angles = np.linspace(0, np.pi, N, dtype=np.float32) ag = AcquisitionGeometry('parallel', '2D', angles, detectors) device = input('Available device: GPU==1 / CPU==0 ') if device == '1': dev = 'gpu' else: dev = 'cpu' Aop = AstraProjectorSimple(ig, ag, dev) sin = Aop.direct(data) noisy_data = AcquisitionData(sin.as_array() + np.random.normal(0, 3, ig.shape)) # Setup and run the CGLS algorithm alpha = 50 Grad = Gradient(ig) # Form Tikhonov as a Block CGLS structure op_CGLS = BlockOperator(Aop, alpha * Grad, shape=(2, 1)) block_data = BlockDataContainer(noisy_data, Grad.range_geometry().allocate()) x_init = ig.allocate() cgls = CGLS(x_init=x_init, operator=op_CGLS, data=block_data) cgls.max_iteration = 1000
ag = AcquisitionGeometry('parallel', '2D', angles, det_num, det_w) elif test_case == 2: angles = np.linspace(0, 2 * np.pi, angles_num, endpoint=False) ag = AcquisitionGeometry('cone', '2D', angles, det_num, det_w, dist_source_center=SourceOrig, dist_center_detector=OrigDetec) else: NotImplemented # Set up Operator object combining the ImageGeometry and AcquisitionGeometry # wrapping calls to ASTRA as well as specifying whether to use CPU or GPU. Aop = AstraProjectorSimple(ig, ag, 'gpu') # Forward and backprojection are available as methods direct and adjoint. Here # generate test data b and do simple backprojection to obtain z. b = Aop.direct(Phantom) z = Aop.adjoint(b) plt.imshow(b.array) plt.title('Simulated data') plt.show() plt.imshow(z.array) plt.title('Backprojected data') plt.colorbar() plt.show()
detectors = int(np.sqrt(2) * N) det_w = 1.0 SourceOrig = 200 OrigDetec = 0 angles = np.linspace(0, 2 * np.pi, angles_num) ag = AcquisitionGeometry('cone', '2D', angles, detectors, det_w, dist_source_center=SourceOrig, dist_center_detector=OrigDetec) else: NotImplemented Aop = AstraProjectorSimple(ig, ag, dev) sin = Aop.direct(data) eta = 0 noisy_data = AcquisitionData(sin.as_array() + np.random.normal(0, 1, ag.shape)) back_proj = Aop.adjoint(noisy_data) # Define Least Squares f = FunctionOperatorComposition(L2NormSquared(b=noisy_data), Aop) # Allocate solution x_init = ig.allocate() # Run FISTA for least squares fista = FISTA(x_init=x_init, f=f, g=ZeroFunction()) fista.max_iteration = 10 fista.update_objective_interval = 2
ig = ImageGeometry(voxel_num_x=N, voxel_num_y=N) data = ImageData(phantom_2D) #Create Acquisition Data detectors = N angles = np.linspace(0, np.pi, 180) ag = AcquisitionGeometry('parallel', '2D', angles, detectors) device = input('Available device: GPU==1 / CPU==0 ') if device == '1': dev = 'gpu' else: dev = 'cpu' Aop = AstraProjectorSimple(ig, ag, 'cpu') sin = Aop.direct(data) # Create noisy sinogram. noises = ['gaussian', 'poisson'] noise = noises[which_noise] if noise == 'poisson': scale = 5 eta = 0 noisy_data = AcquisitionData( np.random.poisson(scale * (eta + sin.as_array())) / scale, ag) elif noise == 'gaussian': n1 = np.random.normal(0, 1, size=ag.shape) noisy_data = AcquisitionData(n1 + sin.as_array(), ag) else:
# 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(geometry=ig2d) # Set tolerance and number of iterations for reconstruction algorithms. opt = {'tol': 1e-4, 'iter': 50} # First a CGLS reconstruction can be done: CGLS_alg = CGLS() CGLS_alg.set_up(x_init, Aop, data2d) CGLS_alg.max_iteration = 2000 CGLS_alg.run(opt['iter']) x_CGLS = CGLS_alg.get_output()