def process(self): IM = self.get_input() #create the output AcquisitionData DATA = AcquisitionData(geometry=self.sinogram_geometry) for k in range(DATA.geometry.channels): sinogram_id, DATA.as_array()[k] = astra.create_sino( IM.as_array()[k], self.proj_id) astra.data2d.delete(sinogram_id) if self.device == 'cpu': return DATA else: if self.sinogram_geometry.geom_type == 'cone': return DATA else: scaling = (1.0 / self.volume_geometry.voxel_size_x) return scaling * DATA
def setupCCPiGeometries(voxel_num_x, voxel_num_y, voxel_num_z, angles, counter): vg = ImageGeometry(voxel_num_x=voxel_num_x,voxel_num_y=voxel_num_y, voxel_num_z=voxel_num_z) Phantom_ccpi = ImageData(geometry=vg, dimension_labels=['horizontal_x','horizontal_y','vertical']) #.subset(['horizontal_x','horizontal_y','vertical']) # ask the ccpi code what dimensions it would like voxel_per_pixel = 1 geoms = pbalg.pb_setup_geometry_from_image(Phantom_ccpi.as_array(), angles, voxel_per_pixel ) pg = AcquisitionGeometry('parallel', '3D', angles, geoms['n_h'], 1.0, geoms['n_v'], 1.0 #2D in 3D is a slice 1 pixel thick ) center_of_rotation = Phantom_ccpi.get_dimension_size('horizontal_x') / 2 ad = AcquisitionData(geometry=pg,dimension_labels=['angle','vertical','horizontal']) geoms_i = pbalg.pb_setup_geometry_from_acquisition(ad.as_array(), angles, center_of_rotation, voxel_per_pixel ) counter+=1 if counter < 4: if (not ( geoms_i == geoms )): print ("not equal and {0}".format(counter)) X = max(geoms['output_volume_x'], geoms_i['output_volume_x']) Y = max(geoms['output_volume_y'], geoms_i['output_volume_y']) Z = max(geoms['output_volume_z'], geoms_i['output_volume_z']) return setupCCPiGeometries(X,Y,Z,angles, counter) else: return geoms else: return geoms_i
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: raise ValueError('Unsupported Noise ', noise) # Show Ground Truth and Noisy Data plt.figure(figsize=(10, 10)) plt.subplot(1, 2, 2) plt.imshow(data.as_array()) plt.title('Ground Truth') plt.colorbar() plt.subplot(1, 2, 1) plt.imshow(noisy_data.as_array()) plt.title('Noisy Data') plt.colorbar() plt.show() # Create operators op1 = Gradient(ig) op2 = Aop # Create BlockOperator operator = BlockOperator(op1, op2, shape=(2, 1)) # Compute operator Norm normK = operator.norm() # Create functions
plt.imshow(b.array) plt.title('Simulated data') plt.colorbar() plt.show() plt.imshow(z.array) plt.title('Backprojected data') plt.colorbar() plt.show() One = ImageData(geometry=ig) xOne = One.as_array() xOne[:,:] = 1.0 OneD = AcquisitionData(geometry=ag) y1 = OneD.as_array() y1[:,:] = 1.0 s1 = (OneD*(Aop.direct(One))).sum() s2 = (One*(Aop.adjoint(OneD))).sum() print(s1) print(s2) print(s2/s1) print((b*b).sum()) print((z*Phantom).sum()) print((z*Phantom).sum() / (b*b).sum()) #print(N/det_num) #print(0.5*det_w/dx)
from mpl_toolkits.axes_grid1 import make_axes_locatable def colorbar(mappable): ax = mappable.axes fig = ax.figure divider = make_axes_locatable(ax) cax = divider.append_axes("right", size="5%", pad=0.15) return fig.colorbar(mappable, cax=cax) fig, ax = plt.subplots(1, 3) img1 = ax[0].imshow(data.as_array()) ax[0].set_title('Ground Truth') colorbar(img1) img2 = ax[1].imshow(noisy_data.as_array()) ax[1].set_title('Projection Data') colorbar(img2) img3 = ax[2].imshow(back_proj.as_array()) ax[2].set_title('BackProjection') colorbar(img3) plt.tight_layout(h_pad=1.5) fig1, ax1 = plt.subplots(1, 3) img4 = ax1[0].imshow(fista.get_output().as_array()) ax1[0].set_title('LS unconstrained') colorbar(img4) img5 = ax1[1].imshow(fista0.get_output().as_array()) ax1[1].set_title('LS constrained [0,1]') colorbar(img5) img6 = ax1[2].imshow(fista1.get_output().as_array())
from ccpi.optimisation.algs import CGLS import numpy # Set up reader object and read the data datareader = XTEKReader("REPLACE_THIS_BY_PATH_TO_DATASET/SophiaBeads_256_averaged.xtekct") data = datareader.get_acquisition_data() # Crop data and fix dimension labels data = AcquisitionData(data.array[:,:,901:1101], geometry=data.geometry, dimension_labels=['angle','horizontal','vertical']) data.geometry.pixel_num_v = 200 # Scale and negative-log transform data.array = -np.log(data.as_array()/60000.0) # Apply centering correction by zero padding, amount found manually cor_pad = 30 data_pad = np.zeros((data.shape[0],data.shape[1]+cor_pad,data.shape[2])) data_pad[:,cor_pad:,:] = data.array data.geometry.pixel_num_h = data.geometry.pixel_num_h + cor_pad data.array = data_pad # Choose the number of voxels to reconstruct onto as number of detector pixels N = data.geometry.pixel_num_h # Geometric magnification mag = (np.abs(data.geometry.dist_center_detector) + \ np.abs(data.geometry.dist_source_center)) / \ np.abs(data.geometry.dist_source_center)
dev = 'cpu' Aop = AstraProjectorSimple(ig, ag, dev) sin = Aop.direct(data) np.random.seed(10) noisy_data = AcquisitionData(sin.as_array() + np.random.normal(0, 1, ag.shape)) # Show Ground Truth and Noisy Data plt.figure(figsize=(10, 10)) plt.subplot(2, 1, 1) plt.imshow(data.as_array()) plt.title('Ground Truth') plt.colorbar() plt.subplot(2, 1, 2) plt.imshow(noisy_data.as_array()) plt.title('Noisy Data') plt.colorbar() plt.show() # Setup and run the simple CGLS algorithm x_init = ig.allocate() cgls1 = CGLS(x_init=x_init, operator=Aop, data=noisy_data) cgls1.max_iteration = 20 cgls1.update_objective_interval = 5 cgls1.run(20, verbose=True) # Setup and run the regularised CGLS algorithm (Tikhonov with Identity) x_init = ig.allocate()
dev = 'gpu' else: dev = 'cpu' Aop = AstraProjectorSimple(ig, ag, dev) sin = Aop.direct(data) projection_data = AcquisitionData(sin.as_array()) # Show Ground Truth and Noisy Data plt.figure(figsize=(10, 10)) plt.subplot(2, 1, 1) plt.imshow(data.as_array()) plt.title('Ground Truth') plt.colorbar() plt.subplot(2, 1, 2) plt.imshow(projection_data.as_array()) plt.title('Projection Data') plt.colorbar() plt.show() # Setup and run the CGLS algorithm x_init = ig.allocate() cgls = CGLS(x_init=x_init, operator=Aop, data=projection_data) cgls.max_iteration = 5000 cgls.update_objective_interval = 100 cgls.run(1000, verbose=True) plt.figure(figsize=(5, 5)) plt.imshow(cgls.get_output().as_array()) plt.title('CGLS reconstruction') plt.colorbar()