一、安装最新版本的cmake

网上的教程下载的cmake版本往往不够新,Ubuntu16.0.4版本下载的是3.5.1的版本,太老了,cmake版本建议在3.19.2以上
StackOverflow上的方法
1、

  1. sudo apt-get update
  2. sudo apt-get install apt-transport-https ca-certificates gnupg \
  3. software-properties-common wget

2、

  1. wget -qO - https://apt.kitware.com/keys/kitware-archive-latest.asc |
  2. sudo apt-key add -

3、

Ubuntu20.0.4

  1. sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main'
  2. sudo apt-get update

Ubuntu18.0.4

  1. sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main'
  2. sudo apt-get update

Ubuntu16.0.4

  1. sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ xenial main'
  2. sudo apt-get update

4、

  1. sudo apt-get install cmake

5、安装ccmake

  1. apt install cmake-curses-gui

Ubuntu用户也可参考:
https://apt.kitware.com/

二、本地ITK的安装(不推荐这种方式)

可参考
1、https://blog.csdn.net/qq_32599479/article/details/80542145
2、https://blog.csdn.net/the_best_man/article/details/109955065?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_baidulandingword-1&spm=1001.2101.3001.4242

三、安装ANTs

创建好文件夹

先在/home/duzh/路径下创建文件夹ANT(根目录自己决定)

  1. mkdir ANT

然后cd ANT, 将ANTs的文件克隆到ANT文件夹下(没有git需要自己安装一下)

  1. git clone https://github.com/ANTsX/ANTs.git

cmake

在ANT文件夹下新建文件夹antsbin, 进入该文件夹,然后cmake编译

  1. mkdir antsbin
  2. cd antsbin
  3. ccmake ../ANTs

按c进行configure,调整好相应参数再按c,最后再按g(generate)
注意CMAKE_INSTALL_PREFIX是你想安装ANTs的位置,推荐放在antsbin文件夹下面,到时候记得在哪里即可
Ubuntu20.0.4 ANTs安装详细步骤(附cmake编译失败解决方案) - 图1
进行编译(三选一,最后一个是多线程编译,适合电脑配置比较好的,出错了可以换第一个试试)

  1. make 2>&1 | tee build.log
  2. make > build.log 2>&1
  3. make -j 2 2>&1 | tee build.log

编译完成之后,进行安装

  1. cd ANTS-build
  2. make install 2>&1 | tee install.log

非root用户使用:
sudo make install 2>&1 | tee install.log

cmake编译出错

由于国内从git clone可能会出现失败的情况,ANT官方的建议是把SuperBuild_ANTS_USE_GIT_PROTOC 关掉(方向键移动上下移动,回车键修改)

1、如果你是使用本地ITK,出现以下错误:

  1. [ 0%] Building CXX object Examples/CMakeFiles/antsUtilities.dir/antsUtilities.cxx.o
  2. [ 1%] Building CXX object Examples/CMakeFiles/antsUtilities.dir/antsRegistrationTemplateHeader.cxx.o
  3. In file included from /home/duzh/ANT/ANTs/Examples/antsRegistrationTemplateHeader.cxx:1:
  4. /home/duzh/ANT/ANTs/Examples/antsRegistrationTemplateHeader.h:21:10: fatal error: itkLabelImageGenericInterpolateImageFunction.h: No such file or directory
  5. 21 | #include "itkLabelImageGenericInterpolateImageFunction.h"
  6. | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. compilation terminated.
  8. make[5]: *** [Examples/CMakeFiles/antsUtilities.dir/build.make:90: Examples/CMakeFiles/antsUtilities.dir/antsRegistrationTemplateHeader.cxx.o] Error 1
  9. make[5]: *** Waiting for unfinished jobs....
  10. make[4]: *** [CMakeFiles/Makefile2:2827: Examples/CMakeFiles/antsUtilities.dir/all] Error 2
  11. make[3]: *** [Makefile:166: all] Error 2
  12. make[2]: *** [CMakeFiles/ANTS.dir/build.make:88: ANTS-prefix/src/ANTS-stamp/ANTS-build] Error 2
  13. make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/ANTS.dir/all] Error 2
  14. make: *** [Makefile:121: all] Error 2

一般是ITK配置的不对,可以参考:

https://github.com/ANTsX/ANTs/issues/817
https://github.com/InsightSoftwareConsortium/ITK/issues/1200
建议采用SuperBuild的模式,采用联网下载ITK的模式,不要使用本地的ITK了

2、如果错误显示不能从github上下载某一个文件

再次运行make -j 2 2>&1 | tee build.log

3、其他错误

参考GitHub上的解决方案 https://github.com/ANTsX/ANTs/wiki
或者Google,能不能在GitHub issue上找到相应解答

四、添加到路径

添加到系统环境,vi ~/.bash_profile
i键编辑

  1. export ANTSPATH=/home/duzh/ANT/antsbin/bin/
  2. export PATH=${ANTSPATH}:$PATH

Esc,再按:wq 退出
保存修改source ~/.bash_profile
注意这个是你cmake的时候填写的CMAKE_INSTALL_PREFIX对应的地址
默认是:

  1. export ANTSPATH=/opt/ANTs/bin/
  2. export PATH=${ANTSPATH}:$PATH

五、检测是否成功安装

  1. which antsRegistration

Ubuntu20.0.4 ANTs安装详细步骤(附cmake编译失败解决方案) - 图2

  1. antsRegistrationSyN.sh

Ubuntu20.0.4 ANTs安装详细步骤(附cmake编译失败解决方案) - 图3
Ubuntu20.0.4 ANTs安装详细步骤(附cmake编译失败解决方案) - 图4
Ubuntu20.0.4 ANTs安装详细步骤(附cmake编译失败解决方案) - 图5

Reference

https://apt.kitware.com/
https://stackoverflow.com/questions/49859457/how-to-reinstall-the-latest-cmake-version

网上其他中文ANTs安装教程

https://blog.csdn.net/qq_32599479/article/details/80542145
https://blog.csdn.net/the_best_man/article/details/109955065?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_baidulandingword-1&spm=1001.2101.3001.4242
https://blog.csdn.net/zuzhiang/article/details/104930000
https://blog.csdn.net/guipeng999/article/details/108237136?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-0&spm=1001.2101.3001.4242
https://zhuanlan.zhihu.com/p/117609588
https://blog.csdn.net/the_best_man/article/details/109955065?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_baidulandingword-1&spm=1001.2101.3001.4242