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 finalImageS = stir.FloatVoxelsOnCartesianGrid( projdata_info, 1, stir.FloatCartesianCoordinate3D(stir.make_FloatCoordinate(0, 0, 0)), stir.IntCartesianCoordinate3D(
zoom = 1.2 image_data = stir.FloatVoxelsOnCartesianGrid(proj_data_info, zoom) #%% initialise a projection matrix # Using ray-tracing here # Note that the default is to restrict the projection to a cylindrical FOV projmatrix = stir.ProjMatrixByBinUsingRayTracing() projmatrix.set_up(proj_data_info, image_data) #%% construct projectors forwardprojector = stir.ForwardProjectorByBinUsingProjMatrixByBin(projmatrix) forwardprojector.set_up(proj_data_info, image_data) backprojector = stir.BackProjectorByBinUsingProjMatrixByBin(projmatrix) backprojector.set_up(proj_data_info, image_data) #%% create projection data for output of forward projection # We'll create the data in memory here exam_info = stir.ExamInfo() projdataout = stir.ProjDataInMemory(exam_info, proj_data_info) # Note: we could write to file, but it is right now a bit complicated to open a # projection data file for read/write: # inout=stir.ios.trunc|stir.ios.ios_base_in|stir.ios.out; # projdataout=stir.ProjDataInterfile(exam_info, proj_data_info, 'my_test_python_projection.hs',inout); #%% Done creating data and projectors! # Let's now create an interesting image with 2 cylinders #%% create a first cylinder (note: units are in mm) # we'll put it in the middle of the scanner # This is currently a bit difficult in STIR due to its # choice of origin (the middle of the first ring). length = 60 radius = 40
#_______________________PROJ MATRIX AND PROJECTORS______________________ slope = 0.0 offSet = 0.0 MotionModel = stir.MotionModel(nFrames, slope, offSet) # A motion model is compulsory 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) #_________________________MEASUREMENT_______________________________ measurement = stir.ProjDataInMemory(stir.ExamInfo(), projdata_info) measurementListP = [] ## First time frame MotionModel.setOffset(0.0) forwardprojector.forward_project(measurement, phantomS[0]) measurement.write_to_file('sinoMeas_1.hs') measurementS = measurement.get_segment_by_sinogram(0) measurementP = stirextra.to_numpy(measurementS) measurementListP.append(measurementP) ## Second time frame MotionModel.setOffset(0.0) # Beweging zit al in het plaatje forwardprojector.forward_project(measurement, phantomS[1]) measurement.write_to_file('sinoMeas_2.hs') measurementS = measurement.get_segment_by_sinogram(0)
#allocate imagespace guestimates guestimatespace = stir.FloatVoxelsOnCartesianGrid( projdata_info, 1, stir.FloatCartesianCoordinate3D(stir.make_FloatCoordinate(0, 0, 0)), stir.IntCartesianCoordinate3D( stir.make_IntCoordinate( np.shape(p)[0], np.shape(p)[1], np.shape(p)[2]))) guestimatespace.fill(1) reconList.append(guestimatespace) # We'll just create the data in memory here measurementList.append( stir.ProjDataInMemory(stir.ExamInfo(), projdata_info)) #forward project last measurement in list forwardprojector.forward_project(measurementList[-1], phantomList[-1]) tmp = measurementList[-1].get_segment_by_sinogram(0) #pyvpx.numpy2vpx(stirextra.to_numpy(tmp), ('MeasuredSinoFrame' + str(iFrame) + '.vpx')) #append empty sinogram for estimations sinogramList.append(stir.ProjDataInMemory(stir.ExamInfo(), projdata_info)) SurrogateSignal = np.array(range(nFrames)) #Normalize NormSpace = stir.FloatVoxelsOnCartesianGrid( projdata_info, 1, stir.FloatCartesianCoordinate3D(stir.make_FloatCoordinate(0, 0, 0)),
#projdata_info = stir.ProjDataInfo.ProjDataInfoCTI(scanner, span, max_ring_diff, 168, scanner.get_max_num_non_arccorrected_bins(), False) projdata_info2D = stir.ProjDataInfo.ProjDataInfoCTI(scanner, span, max_ring_diff, 168, scanner.get_max_num_non_arccorrected_bins(), False) guessVolume = stir.FloatVoxelsOnCartesianGrid(projdata_info2D, 1, stir.FloatCartesianCoordinate3D(stir.make_FloatCoordinate(0,0,0)), stir.IntCartesianCoordinate3D(stir.make_IntCoordinate(sizeOfVolumeInVoxels[0], sizeOfVolumeInVoxels[1], sizeOfVolumeInVoxels[2]))) guessVolume.fill(1) ErrorVolume = stir.FloatVoxelsOnCartesianGrid(projdata_info2D, 1, stir.FloatCartesianCoordinate3D(stir.make_FloatCoordinate(0,0,0)), stir.IntCartesianCoordinate3D(stir.make_IntCoordinate(sizeOfVolumeInVoxels[0], sizeOfVolumeInVoxels[1], sizeOfVolumeInVoxels[2]))) ErrorVolume.fill(0) forwardSino2D = stir.ProjDataInMemory(stir.ExamInfo(), projdata_info2D) forwardSino2D.fill(0) #Initialize the projection matrix (using ray-tracing) projmatrix2D = stir.ProjMatrixByBinUsingRayTracing() nLOR = 10 projmatrix2D.set_num_tangential_LORs(nLOR) projmatrix2D.set_up(projdata_info2D, guessVolume) #Create projectors forwardprojector2D = stir.ForwardProjectorByBinUsingProjMatrixByBin(projmatrix2D) backprojector2D = stir.BackProjectorByBinUsingProjMatrixByBin(projmatrix2D) def forwardProject(npSource): guessVolume.fill(npSource.flat) forwardSino2D.fill(0)
def test_shape(): s = stir.Scanner.get_scanner_from_name("ECAT 962") projdatainfo = stir.ProjDataInfo.ProjDataInfoCTI(s, 3, 9, 8, 6) projdata = stir.ProjDataInMemory(stir.ExamInfo(), projdatainfo) shape = get_shape_from_proj_data(projdata) assert shape == projdata.to_array().shape()