def process(self): projections = self.get_input() projections_axes = projections.get_data_axes_order(new_order=self.default_acquisition_axes_order) if not projections_axes == [0,1,2]: projections.array = numpy.transpose(projections.array, projections_axes) pixel_per_voxel = 1 # should be estimated from image_geometry and acquisition_geometry image_geometry = ImageGeometry(voxel_num_x = self.acquisition_geometry.pixel_num_h, voxel_num_y = self.acquisition_geometry.pixel_num_h, voxel_num_z = self.acquisition_geometry.pixel_num_v) # input centered/padded acquisitiondata center_of_rotation = projections.get_dimension_size('horizontal') / 2 if self.acquisition_geometry.geom_type == 'parallel': back = pbalg.pb_backward_project( projections.as_array(), self.acquisition_geometry.angles, center_of_rotation, pixel_per_voxel ) out = ImageData(geometry=self.image_geometry, dimension_labels=self.default_image_axes_order) out_axes = out.get_data_axes_order(new_order=self.output_axes_order) if not out_axes == [0,1,2]: back = numpy.transpose(back, out_axes) out.fill(back) return out else: raise ValueError('Cannot process cone beam')
def test_FISTA(self): print ("Test FISTA") ig = ImageGeometry(127,139,149) x_init = ImageData(geometry=ig) b = x_init.copy() # fill with random numbers b.fill(numpy.random.random(x_init.shape)) x_init = ImageData(geometry=ig) x_init.fill(numpy.random.random(x_init.shape)) identity = TomoIdentity(geometry=ig) norm2sq = Norm2sq(identity, b) opt = {'tol': 1e-4, 'memopt':False} alg = FISTA(x_init=x_init, f=norm2sq, g=None, opt=opt) alg.max_iteration = 2 alg.run(20, verbose=True) self.assertNumpyArrayAlmostEqual(alg.x.as_array(), b.as_array()) alg.run(20, verbose=True) self.assertNumpyArrayAlmostEqual(alg.x.as_array(), b.as_array())
def test_BlockDataContainer_fill(self): print("test block data container") ig0 = ImageGeometry(2, 3, 4) ig1 = ImageGeometry(2, 3, 5) data0 = ImageData(geometry=ig0) data1 = ImageData(geometry=ig1) + 1 data2 = ImageData(geometry=ig0) + 2 data3 = ImageData(geometry=ig1) + 3 cp0 = BlockDataContainer(data0, data1) #cp1 = BlockDataContainer(data2,data3) cp2 = BlockDataContainer(data0 + 1, data1 + 1) data0.fill(data2) self.assertNumpyArrayEqual(data0.as_array(), data2.as_array()) data0 = ImageData(geometry=ig0) for el, ot in zip(cp0, cp2): print(el.shape, ot.shape) cp0.fill(cp2) self.assertBlockDataContainerEqual(cp0, cp2)
def create_image_data(self): x0 = ImageData(geometry = self.volume_geometry, dimension_labels=self.bp.output_axes_order)#\ #.subset(['horizontal_x','horizontal_y','vertical']) x0.fill(numpy.random.randn(*x0.shape)) return x0
# Set up empty image data Phantom = ImageData( geometry=ig, dimension_labels=['horizontal_x', 'horizontal_y', 'vertical']) # Populate image data by looping over and filling slices i = 0 while i < vert: if vert > 1: x = Phantom.subset(vertical=i).array else: x = Phantom.array x[round(N / 4):round(3 * N / 4), round(N / 4):round(3 * N / 4)] = 0.5 x[round(N / 8):round(7 * N / 8), round(3 * N / 8):round(5 * N / 8)] = 0.98 if vert > 1: Phantom.fill(x, vertical=i) i += 1 # Display slice of phantom if vert > 1: plt.imshow(Phantom.subset(vertical=0).as_array()) else: plt.imshow(Phantom.as_array()) plt.show() # Set up AcquisitionGeometry object to hold the parameters of the measurement # setup geometry: # Number of angles, the actual angles from 0 to # pi for parallel beam, set the width of a detector # pixel relative to an object pixe and the number of detector pixels. angles_num = 20 det_w = 1.0