此页面是从 /doc/source/ipynb/tomopy.ipynb. 互动在线版:
使用TomoPy进行重建¶
以下是如何使用GRIDERC的示例 [B5] 重建算法,具有 TomoPy [A1] 。
第一 install TomoPy。
[1]:
import tomopy
支持以TomoPy格式输入的断层扫描数据 DXchange 。
[2]:
import dxchange
Matplotlib 在本笔记本中提供结果的绘图。 Paraview 或者其他工具可用于更复杂的3D渲染。
[3]:
import matplotlib.pyplot as plt
如果需要,可以导入并激活Python的内置日志记录模块。它可能会打印一些有用的东西。
[4]:
import logging
logging.basicConfig(level=logging.INFO)
这 data set 文件格式遵循 APS 光束线 2-BM and 32-ID data-exchange 定义。用于其他同步加速器的其他文件格式读取器也可通过 DXchange 。
[5]:
proj, flat, dark, theta = dxchange.read_aps_32id(
fname='../../../source/tomopy/data/tooth.h5',
sino=(0, 2), # Select the sinogram range to reconstruct.
)
INFO:dxchange.reader:Data successfully imported: /home/dching/Documents/tomopy/source/tomopy/data/tooth.h5
INFO:dxchange.reader:Data successfully imported: /home/dching/Documents/tomopy/source/tomopy/data/tooth.h5
INFO:dxchange.reader:Data successfully imported: /home/dching/Documents/tomopy/source/tomopy/data/tooth.h5
INFO:dxchange.reader:Data successfully imported: /home/dching/Documents/tomopy/source/tomopy/data/tooth.h5
绘制正弦图形
[6]:
plt.imshow(proj[:, 0, :])
plt.show()
如果无法从原始数据获得角度信息,则需要设置数据采集角度。在这种情况下, theta
被设置为在0-180度之间等间距。
[7]:
if theta is None:
theta = tomopy.angles(proj.shape[0])
执行原始数据的平场校正:
\[\crc{投影-暗}{平面-暗}\]
[8]:
proj = tomopy.normalize(proj, flat, dark)
计算$-log(Proj)$以线性化传输断层扫描数据。
[9]:
proj = tomopy.minus_log(proj)
Tomopy提供了各种方法 ([B12] , [B25] , [B16] )至 find the rotation center 。
[10]:
rot_center = tomopy.find_center(proj, theta, init=290, ind=0, tol=0.5)
INFO:tomopy.recon.rotation:Trying rotation center: [290.]
INFO:tomopy.recon.rotation:Function value = 2.014651
INFO:tomopy.recon.rotation:Trying rotation center: [304.5]
Reconstructing 1 slice groups with 1 master threads...
Reconstructing 1 slice groups with 1 master threads...
Reconstructing 1 slice groups with 1 master threads...
INFO:tomopy.recon.rotation:Function value = 2.076837
INFO:tomopy.recon.rotation:Trying rotation center: [275.5]
INFO:tomopy.recon.rotation:Function value = 2.259117
INFO:tomopy.recon.rotation:Trying rotation center: [297.25]
INFO:tomopy.recon.rotation:Function value = 1.920647
INFO:tomopy.recon.rotation:Trying rotation center: [304.5]
Reconstructing 1 slice groups with 1 master threads...
Reconstructing 1 slice groups with 1 master threads...
Reconstructing 1 slice groups with 1 master threads...
INFO:tomopy.recon.rotation:Function value = 2.076837
INFO:tomopy.recon.rotation:Trying rotation center: [293.625]
INFO:tomopy.recon.rotation:Function value = 1.939667
INFO:tomopy.recon.rotation:Trying rotation center: [300.875]
INFO:tomopy.recon.rotation:Function value = 1.997986
INFO:tomopy.recon.rotation:Trying rotation center: [295.4375]
Reconstructing 1 slice groups with 1 master threads...
Reconstructing 1 slice groups with 1 master threads...
Reconstructing 1 slice groups with 1 master threads...
INFO:tomopy.recon.rotation:Function value = 1.908336
INFO:tomopy.recon.rotation:Trying rotation center: [293.625]
INFO:tomopy.recon.rotation:Function value = 1.939667
INFO:tomopy.recon.rotation:Trying rotation center: [296.34375]
INFO:tomopy.recon.rotation:Function value = 1.906685
INFO:tomopy.recon.rotation:Trying rotation center: [297.25]
Reconstructing 1 slice groups with 1 master threads...
Reconstructing 1 slice groups with 1 master threads...
Reconstructing 1 slice groups with 1 master threads...
INFO:tomopy.recon.rotation:Function value = 1.920647
INFO:tomopy.recon.rotation:Trying rotation center: [295.890625]
INFO:tomopy.recon.rotation:Function value = 1.906942
Reconstructing 1 slice groups with 1 master threads...
使用GRIDERC算法进行重建。Tomopy提供了各种 reconstruction 并为其他库提供包装器,如 ASTRA toolbox 。
[11]:
recon = tomopy.recon(proj, theta, center=rot_center, algorithm='gridrec', sinogram_order=False)
Reconstructing 2 slice groups with 2 master threads...
用一个圆圈遮盖每个重建的切片。
[12]:
recon = tomopy.circ_mask(recon, axis=0, ratio=0.95)
[13]:
plt.imshow(recon[0, :, :])
plt.show()
[ ]: