def __init__(self, domain, range, volume, proj_data, projector=None, adjoint=None): """Initialize a new instance. Parameters ---------- domain : `DiscreteLp` Volume of the projection. Needs to have the same shape as ``volume.shape()``. range : `DiscreteLp` Projection space. Needs to have the same shape as ``proj_data.to_array().shape()``. volume : ``stir.FloatVoxelsOnCartesianGrid`` Stir volume to use in the forward projection proj_data : ``stir.ProjData`` Stir description of the projection. projector : ``stir.ForwardProjectorByBin``, optional A pre-initialized projector. adjoint : `BackProjectorByBinWrapper`, optional A pre-initialized adjoint. """ # Check data sizes if domain.shape != volume.shape(): raise ValueError('domain.shape {} does not equal volume shape {}' ''.format(domain.shape, volume.shape())) # TODO: improve proj_shape = proj_data.to_array().shape() if range.shape != proj_shape: raise ValueError('range.shape {} does not equal proj shape {}' ''.format(range.shape, proj_shape)) # Set domain, range etc super().__init__(domain, range, True) # Read template of the projection self.proj_data = proj_data self.proj_data_info = proj_data.get_proj_data_info() self.volume = volume # Create forward projection by matrix if projector is None: proj_matrix = stir.ProjMatrixByBinUsingRayTracing() proj_matrix.set_up(self.proj_data_info, self.volume) self.projector = stir.ForwardProjectorByBinUsingProjMatrixByBin( proj_matrix) self.projector.set_up(self.proj_data_info, self.volume) # If no adjoint was given, we initialize a projector here to # save time. if adjoint is None: back_projector = stir.BackProjectorByBinUsingProjMatrixByBin( proj_matrix) back_projector.set_up(self.proj_data.get_proj_data_info(), self.volume) else: # If user wants to provide both a projector and a back-projector, # he should wrap the back projector in an Operator self.projector = projector back_projector = None # Pre-create an adjoint to save time if adjoint is None: self._adjoint = BackProjectorByBinWrapper(self.range, self.domain, self.volume, self.proj_data, back_projector, self) else: self._adjoint = adjoint
np.shape(originalImageP)[1], np.shape(originalImageP)[2]))) # Filling the stir data format with the original image fillStirSpace(originalImageS, originalImageP) # Initialize the projection matrix (using ray-tracing) # Het motion model doet nu niets, maar is nodig omdat Stir anders flipt MotionModel = stir.MotionModel() MotionModel.setOffset(0.0) projmatrix = stir.ProjMatrixByBinUsingRayTracing(MotionModel) projmatrix.set_num_tangential_LORs(nLOR) projmatrix.set_up(projdata_info, originalImageS) # Create projectors forwardprojector = stir.ForwardProjectorByBinUsingProjMatrixByBin(projmatrix) backprojector = stir.BackProjectorByBinUsingProjMatrixByBin(projmatrix) # Creating an instance for the sinogram (measurement), it is not yet filled measurement = stir.ProjDataInMemory(stir.ExamInfo(), projdata_info) # Forward project originalImageS and store in measurement forwardprojector.forward_project(measurement, originalImageS) # Converting the stir sinogram to a numpy sinogram measurementS = measurement.get_segment_by_sinogram(0) measurementP = stirextra.to_numpy(measurementS) #plt.figure(2), plt.title('Sinogram original image'), plt.imshow(measurementP[0,:,:]), plt.show() # Backprojecting the sinogram to get an image
def __init__(self, domain, range, volume, proj_data, back_projector=None, adjoint=None): """Initialize a new instance. Parameters ---------- domain : `DiscreteLp` Projection space. Needs to have the same shape as ``proj_data.to_array().shape()``. range : `DiscreteLp` Volume of the projection. Needs to have the same shape as ``volume.shape()``. volume : ``stir.FloatVoxelsOnCartesianGrid`` Stir volume to use in the forward projection proj_data : ``stir.ProjData`` Stir description of the projection. back_projector : ``stir.BackProjectorByBin``, optional A pre-initialized back-projector. adjoint : `ForwardProjectorByBinWrapper`, optional A pre-initialized adjoint. Notes ----- See `STIR doc`_ for info on the STIR classes. References ---------- .. _STIR doc: http://stir.sourceforge.net/documentation/doxy/html/ """ # Check data sizes if range.shape != volume.shape(): raise ValueError('`range.shape` {} does not equal volume shape {}' ''.format(range.shape, volume.shape())) # TODO: improve proj_shape = proj_data.to_array().shape() if domain.shape != proj_shape: raise ValueError('`domain.shape` {} does not equal proj shape {}' ''.format(range.shape, proj_shape)) # Set range domain super().__init__(domain, range, True) # Read template of the projection self.proj_data = proj_data self.proj_data_info = proj_data.get_proj_data_info() self.volume = volume # Create forward projection by matrix if back_projector is None: proj_matrix = stir.ProjMatrixByBinUsingRayTracing() proj_matrix.set_up(self.proj_data_info, self.volume) self.back_projector = stir.BackProjectorByBinUsingProjMatrixByBin( proj_matrix) self.back_projector.set_up(self.proj_data.get_proj_data_info(), self.volume) if adjoint is None: projector = stir.ForwardProjectorByBinUsingProjMatrixByBin( proj_matrix) projector.set_up(self.proj_data_info, self.volume) else: self.back_projector = back_projector projector = None # Pre-create an adjoint to save time if adjoint is None: self._adjoint = ForwardProjectorByBinWrapper( self.range, self.domain, self.volume, self.proj_data, projector, self) else: self._adjoint = adjoint