最近需要对CT图像进行配准,于是学一下这个工具
(不知道为啥总把这个名字记成 SimpleElastic,其实人家是 SimpleElastix
1、官方手册:https://simpleelastix.readthedocs.io/HelloWorld.html
2、很有用的博文:医学图像配准工具SimpleElastix的配置和入门
就是有几处描述我有点误解,好在后来解决了
之前安装了sitk,以为这个SimpleElastix是集成在sitk里的一个小模块,其实不是,直接调用会报错
AttributeError: 'SimpleITK' object has no attribute 'GetDefaultParameterMap'。
实际上
SimpleElastix虽然会调用SimpleITK,但是这里的SimpleITK并不是简单的标准库SimpleITK,而是SimpleElastix的Gtihub代码里自定义的SimpleITK文件。
即SimpleElastix的SimpleITK包含了标准库SimpleITK和其他自定义函数,必须先区分好这两者的区别否则会出错。
于是按照官方文档 https://simpleelastix.readthedocs.io/GettingStarted.html 安装
$ git clone https://github.com/SuperElastix/SimpleElastix $ mkdir build $ cd build $ cmake ../SimpleElastix/SuperBuild $ make -j4
结合医学图像配准工具SimpleElastix的配置和入门的经验,整个过程没什么问题,就是时间长了一点。
就是后面下载、本地编译的时间非常长,大约要1.5h,需要足够耐心。
- 由于这里是本地编译的,所以他并没有装到你的conda虚拟环境的 /home/anaconda3/envs/你的虚拟环境名字/lib/python3.7/site-packages里边,而是在你执行 git clone 的目录
- 上面的博文里也提到了在导入包的时候要特别注意,直接import SimpleITK as sitk 导入的是标准的sitk包,而不是SimpleElastix自定义的SimpleITK,因此需要先定位到编译的位置
- 我按照上面的博文定位,报错说找不到sitk!我找了一下附近的文件夹,发现在../build/SimpleITK-build/Wrapping/Python/Packaging/build/lib.linux-x86_64-3.7/SimpleITK找到了 __init __.py 和 SimpleITK.py(可能是版本更新调整过位置了?)
import sys sys.path.insert(0, '../build/SimpleITK-build/Wrapping/Python/Packaging/build/lib.linux-x86_64-3.7/SimpleITK') #定位到SimpleElastix安装路径 这里我和上面的文章的目录不同! import SimpleITK as sitk # 导入SimpleElastix自定义的SimpleITK而不是标准库SimpleITK
导入成功!可以开始用了!
具体使用注意输入的文件用的是sitk.ReadImage()得到的image,之前取了其中的iamge中的Array再做配准,报错了。
会输出很多过程信息
Installing all components. InstallingComponents was successful. ELASTIX version: 5.000 Command line options from ElastixBase: -fMask unspecified, so no fixed mask used -mMask unspecified, so no moving mask used -out ./ -threads unspecified, so all available threads are used WARNING: The parameter "UseDirectionCosines", requested at entry number 0, does not exist at all. The default value "true" is used instead. WARNING: The option "UseDirectionCosines" was not found in your parameter file. From elastix 4.8 it defaults to true! This may change the behavior of your registrations considerably. Command line options from TransformBase: -t0 unspecified, so no initial transform used Reading images... Reading images took 0 ms. WARNING: the fixed pyramid schedule is not fully specified! A default pyramid schedule is used. WARNING: the moving pyramid schedule is not fully specified! ... ( SigmoidMin -0.395959 -0.416811 -0.671650 -0.744389 ) ( SigmoidScale 0.000012 0.000019 0.000023 0.000020 ) Time spent on saving the results, applying the final transform etc.: 4580 ms.时间对比
- 虽然官方教程里给的是2D图像配准到2D图像,我试了一下,3D的图像也可以配到3D图像的。
- 刚性配准和仿射配准都很快,27s就结束了
- 但是非刚性变换Non-rigid Registration就很慢了…13m53s才结束
SimpleElastix提供的配准方式
| 配准方式 | 进行的调整 |
|---|---|
| 刚性配准 Rigid Registration | 平移、旋转 |
| 仿射配准 Affine Registration | 平移、旋转、剪切、缩放 |
| 非刚性配准 Non-rigid Registration | free-form deformation (FFD) field自由形变场 常用B-splines B样条处理 |
| 分组配准 Groupwise Registration | 通过同时将所有图像配准到一个总体中来减少与任何一幅图像相关的不确定性。这包含了配准过程中的所有图像信息,消除了对所选参考帧的偏差 |
| 基于点的配准 Point-based Registation | 通过预先定义的对应点集来帮助配准 |


![[医学图像配准] SimpleElastix的安装与简单使用 [医学图像配准] SimpleElastix的安装与简单使用](http://www.mshxw.com/aiimages/31/977890.png)
