Elastix配准工具使用入门

来源:互联网 发布:硬盘恢复数据价格 编辑:程序博客网 时间:2024/05/18 02:00

Elastix介绍

首先根据Elastix官方手册上所写:

elastix. The software consists of a collection of algorithms that are commonly used to solve medical image registration problems. A large part of the code is based on the Insight Toolkit (ITK).The modular design of elastix allows the user to quickly test and compare different registration methods for his/her specific application. ——elastix_manual_v4.7

Elastix是一个基于ITK开发的处理医学图像配准问题的工具。关于什么是医学图像配准,我会再做其他介绍,这里就认为找到Elastix的人都已经有所了解。Elastix提供了很方便的命令行使用方式以供使用者进行配准应用。
同时Elastix是开源的,并且采用模块式构成。可以根据源代码进行开发,或者添加新的模块。使用Elastix的源码需要遵循一些开源的规则,如果有使用需求,可以进行了解。

通过Elastix官方网站可以下载到Elastix的程序、源码、使用手册以及一些相关的文献。并且网站上还说明了当使用Elastix时,已经认为引用了一些参考文献。

Elastix的使用

Elastix使用起来非常方便。在Elastix下载可以下载到Elastix的资源。其中Manual是使用手册(推荐阅读)、Example_of_usage是一个使用的小例子、Source code是源代码,其余的几项分别是不同系统环境下的可执行程序。

作为简单例子,我们可以首先下载Example_of_usage和基于自己系统环境的可执行程序。我的操作系统是64位win8,所以我下载了Windows 64 bit binaries版本。

  • 下载完成后是两个压缩文件,可将可执行文件解压到任何地方(如D:\Elastix),解压后有4个文件。其中elastix.exe是进行配准的程序,transformix.exe是根据配准所得结果对图像进行变换的程序。另外还有一个动态链接库和一个拷贝说明。
  • 因为需要使用Elastix的可执行程序,所以可将elastix_example解压到Elastix目录下。如果想在系统任何地方使用Elastix,可以将Elastix所在目录加入系统环境变量(在Path环境变量中加入Elastix所在路径)。
  • 打开elastix_example,可以看到一个example.bat脚本和一个exampleinput目录。example.bat脚本是对Elastix程序进行调用的脚本,exampleinput目录下存放着需要输入的图像和对Elastix进行配置的参数文件。
  • 双击运行example.bat,可以看到配准程序开始运行,运行成功后会生成exampleoutput文件夹,里边存放配准过程的日志信息,以及配准所得的形变参数等。其中result.0.mhd类的文件为对moving image配准所得的结果,中间的数字代表是使用第几个参数文件(也就是第几轮,刚性或者非刚性)配准所得的。
  • 至此使用Elastix进行配准的简单例子已经完成,更多说明可以参考Elastix的使用手册。

对于配准效果,我们可以首先看一下原始图像的叠加效果:
原始图像的叠加

这幅图是将moving_image叠加到fixed_image上,可以看到粉色部分是moving_image,绿色部分是没有被遮住的fixed_image,两幅图相差不太大,但不完全一样。

再看一下将通过刚性变换后的moving_image叠加到fixed_image上的效果:
刚性变换后

可以看出似乎好了一些,但仍旧不明显。因为没有明显的仿射变换(旋转平移放缩),所以刚性变换并未起到很大作用。

最后看一下通过非刚性变换后的moving_image叠加到fixed_image上的效果:
非刚性变换后
已经看不到绿色部分,过非刚性变换后的moving_image已经基本将fixed_image完全遮盖,证明配准效果有效。

Elastix脚本文件简单说明

上文提到Elastix例子是通过运行example.bat来完成的。使用文本编辑器打开example.bat,可以看到很多内容,其中大部分是注释,最重要的是以下两行:

mkdir exampleoutputelastix -f exampleinput/fixed.mhd -m exampleinput/moving.mhd -out exampleoutput -p exampleinput/parameters_Rigid.txt -p exampleinput/parameters_BSpline.txt

第一行是生成了exampleoutput文件夹。第二行是调用了elastix进行配准。其中参数的意义分别是:

-f exampleinput/fixed.mhd   //fixed image是exampleinput下的fixed.mhd-m exampleinput/moving.mhd  //moving image是exampleinput下的moving.mhd-out exampleoutput          //输出文件夹为exampleoutput           -p exampleinput/parameters_Rigid.txt        //第一轮配准使用的参数存放在exampleinput下的parameters_Rigid.txt文件中-p exampleinput/parameters_BSpline.txt  //第二轮配准使用的参数存放在exampleinput下的parameters_BSpline.txt文件中

在此我们可以看到使用了两个参数文件:parameters_Rigid.txt和parameters_BSpline.txt。其中parameters_Rigid.txt是进行刚性配准的参数文件,parameters_BSpline.txt是使用B样条进行非刚性配准的参数文件。在使用elastix时,输入几个参数文件,就会进行几次配准。通常首先进行刚性配准,后再进行非刚性配准会得到较好的配准效果。

除了对配准进行调用的命令外,还有一行没有被注释的命令是:

transformix -jac all -out exampleoutput -tp exampleoutput/TransformParameters.1.txt

此行的命令是这样介绍的:

In addition to computing the deformation field, transformix has the capability to compute the spatial Jacobian of the transformation.

我目前还不是很了解the spatial Jacobian代表什么,再次就不多做说明。我在此处使用时多将此行替换为

transformix -in inputImage.ext -out outputDirectory -tp TransformParameters.txt

这种格式,来将变形应用到输入的inputImage.ext文件上。其中TransformParameters.txt是配准所得的exampleoutput文件夹中的TransformParameters.1.txt,中间的数字代表是使用第几个参数文件(也就是第几轮,刚性或者非刚性)配准所得的。

关于Elastix参数文件

parameters_Rigid.txt和parameters_BSpline.txt是elastix例子自带的参数文件,我们可以重写这些参数文件,还可以从Parameter_file_database下载到别人使用过的参数文件,以供参考。
参数文件的设置在Elastix使用手册中有所介绍,需要改动的可以参考使用手册。我以后也会做简单介绍。

至此,Elastix配准工具使用入门就介绍完成,希望大家能够灵活应用Elastix完成工作。

资源分享

我将自己下载的Elastix4.7的可执行文件、源码、例子以及使用手册放在了百度云,方便大家下载。

Reference

  1. S. Klein, M. Staring, K. Murphy, M.A. Viergever, J.P.W. Pluim, “elastix: a toolbox for intensity based medical image registration,” IEEE Transactions on Medical Imaging, vol. 29, no. 1, pp. 196 - 205, January 2010.
  2. D.P. Shamonin, E.E. Bron, B.P.F. Lelieveldt, M. Smits, S. Klein and M. Staring, “Fast Parallel Image Registration on CPU and GPU for Diagnostic Classification of Alzheimer’s Disease”, Frontiers in Neuroinformatics, vol. 7, no. 50, pp. 1-15, January 2014.
  3. elastix_manual_v4.7——Stefan Klein and Marius Staring February 12, 2014
1 0
原创粉丝点击