Installation
1.conda create -n pytomography_env -c conda-forge libparallelproj parallelproj pytorch cupy cudatoolkit=11.8
注意可能会因为CUDA版本问题而报错,最好在创建虚拟环境的时候设置好版本
python -c "import parallelproj" 检验是否成功,并且可以测试官方案例
2. pip install pytomography
接下来按照官方案例去跑即可
Load data
1.加载scanner的参数
2.加载listmode数据
Set parameter
# Specify object space for reconstruction
object_meta = ObjectMeta(
dr=(1,1,1), #mm
shape=(240,240,240) #voxels
)
# Get projection space metadata from PET geometry information dictionary
proj_meta = PETLMProjMeta(
detector_ids = detector_ids, # list of all detected event detector ID pairs
info = info
# weights_sensitivity=normalization_weights
)
psf_transform = GaussianFilter(3.25) # gaussian blurring
# Create system matrix
system_matrix = PETLMSystemMatrix(
object_meta,
proj_meta,
obj2obj_transforms = [psf_transform],
# attenuation_map = atten_map,
# N_splits=8,
)
# Create likelihood. For listmode reconstruction, projections don't need to be provided, since all detection events are stored in proj_meta
likelihood = PoissonLogLikelihood(
system_matrix
)
# Initialize reconstruction algorithm
recon_algorithm = OSEM(likelihood)
# Reconstruct
recon_primaryonly = recon_algorithm(n_iters=50, n_subsets=1)
可视化成像结果
vmax = 0.5
fig, ax = plt.subplots(1,3,figsize=(12,4))
plt.subplot(131)
plt.pcolormesh(recon_primaryonly[120,16:-16].cpu().T, cmap='gray', shading='gouraud', vmax=vmax)
plt.axis('off')
plt.subplot(132)
plt.pcolormesh(recon_primaryonly[16:-16,120].cpu().T, cmap='gray', shading='gouraud', vmax=vmax)
plt.axis('off')
plt.subplot(133)
plt.pcolormesh(recon_primaryonly[:,:,120].cpu().T, cmap='gray', shading='gouraud', vmax=vmax)
plt.axis('off')
fig.tight_layout()
plt.show()