scanner = ppp.RegularPolygonPETScanner(ncrystals_per_module=np.array([16, 1]), nmodules=np.array([28, 1])) # setup a test image voxsize = np.array([2., 2., 2.]) n0 = 120 n1 = 120 n2 = max(1, int((scanner.xc2.max() - scanner.xc2.min()) / voxsize[2])) # setup a random image img = np.zeros((n0, n1, n2), dtype=np.float32) img[(n0 // 4):(3 * n0 // 4), (n1 // 4):(3 * n1 // 4), :] = 1 img_origin = (-(np.array(img.shape) / 2) + 0.5) * voxsize # generate sinogram parameters and the projector sino_params = ppp.PETSinogramParameters(scanner, ntofbins=17, tofbin_width=15.) proj = ppp.SinogramProjector(scanner, sino_params, img.shape, nsubsets=1, voxsize=voxsize, img_origin=img_origin, ngpus=ngpus, tof=True, sigma_tof=60. / 2.35, n_sigmas=3.) img_fwd = proj.fwd_project(img, subset=0) # generate sensitity sinogram (product from attenuation and normalization sinogram) # this sinogram is usually non TOF! which results in a different shape
# setup a scanner scanner = ppp.RegularPolygonPETScanner(ncrystals_per_module=np.array([16, 1]), nmodules=np.array([28, 1])) # setup a test image voxsize = np.array([2., 2., 2.]) n0 = 120 n1 = 120 n2 = max(1, int((scanner.xc2.max() - scanner.xc2.min()) / voxsize[2])) # setup a random image img = np.random.rand(n0, n1, n2) img_origin = (-(np.array(img.shape) / 2) + 0.5) * voxsize ######## nontof projections sino_params = ppp.PETSinogramParameters(scanner) proj = ppp.SinogramProjector(scanner, sino_params, img.shape, nsubsets=nsubsets, voxsize=voxsize, img_origin=img_origin, ngpus=ngpus) # setup a random sinogram rsino = np.random.rand(*proj.subset_sino_shapes[subset]) img_fwd = proj.fwd_project(img, subset=subset) back = proj.back_project(rsino, subset=subset) # check if fwd and back projection are adjoint
for i2 in range(n2): img[:, :, i2] = tmp elif phantom == 'brain2d': n = 128 img = np.zeros((n, n, n2), dtype=np.float32) tmp = brain2d_phantom(n=n) for i2 in range(n2): img[:, :, i2] = tmp img_origin = (-(np.array(img.shape) / 2) + 0.5) * voxsize # setup an attenuation image att_img = (img > 0) * 0.01 * voxsize[0] # generate nonTOF sinogram parameters and the nonTOF projector for attenuation projection sino_params = ppp.PETSinogramParameters(scanner, rtrim=146) proj = ppp.SinogramProjector(scanner, sino_params, img.shape, nsubsets=1, voxsize=voxsize, img_origin=img_origin, ngpus=ngpus) attn_sino = np.exp(-proj.fwd_project(att_img)) # generate the sensitivity sinogram sens_sino = np.ones(sino_params.shape, dtype=np.float32) # forward project the image img_fwd = ppp.pet_fwd_model(img, proj, attn_sino, sens_sino, 0, fwhm=fwhm_data)
nmodules = np.array([28,5])) # setup a test image voxsize = np.array([2.,2.,2.]) n0 = 250 n1 = 250 n2 = max(1,int((scanner.xc2.max() - scanner.xc2.min()) / voxsize[2])) # setup a random image img = np.zeros((n0,n1,n2), dtype = np.float32, order = img_mem_order) img[(n0//6):(5*n0//6),(n1//6):(5*n1//6),:] = 1 img_origin = (-(np.array(img.shape) / 2) + 0.5) * voxsize # generate sinogram parameters and the projector sino_params = ppp.PETSinogramParameters(scanner, ntofbins = ntofbins, tofbin_width = 23., spatial_dim_order = spatial_dim_order) proj = ppp.SinogramProjector(scanner, sino_params, img.shape, nsubsets = nsubsets, voxsize = voxsize, img_origin = img_origin, ngpus = ngpus, tof = tof, sigma_tof = 60./2.35, n_sigmas = 3., threadsperblock = tpb) # contamination sinogram with scatter and randoms # useful to avoid division by 0 in the ratio of data and exprected data ones_sino = np.ones(proj.subset_sino_shapes[0], dtype = np.float32) #------------------------------------------------------------------------------------- # time sino fwd and back projection # do a forward / back projection of subset 0 - same as img_fwd = proj.fwd_project(img, 0) # we just write out the single steps to time the python overhead separately t_sino_fwd = np.zeros(n)