一、安装最新版本的cmake
网上的教程下载的cmake版本往往不够新,Ubuntu16.0.4版本下载的是3.5.1的版本,太老了,cmake版本建议在3.19.2以上
StackOverflow上的方法:
1、
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates gnupg \
software-properties-common wget
2、
wget -qO - https://apt.kitware.com/keys/kitware-archive-latest.asc |
sudo apt-key add -
3、
Ubuntu20.0.4
sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main'
sudo apt-get update
Ubuntu18.0.4
sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main'
sudo apt-get update
Ubuntu16.0.4
sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ xenial main'
sudo apt-get update
4、
sudo apt-get install cmake
5、安装ccmake
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
(根目录自己决定)
mkdir ANT
然后cd ANT
, 将ANTs的文件克隆到ANT
文件夹下(没有git需要自己安装一下)
git clone https://github.com/ANTsX/ANTs.git
cmake
在ANT文件夹下新建文件夹antsbin
, 进入该文件夹,然后cmake编译
mkdir antsbin
cd antsbin
ccmake ../ANTs
按c进行configure,调整好相应参数再按c,最后再按g(generate)
注意CMAKE_INSTALL_PREFIX
是你想安装ANTs的位置,推荐放在antsbin
文件夹下面,到时候记得在哪里即可
进行编译(三选一,最后一个是多线程编译,适合电脑配置比较好的,出错了可以换第一个试试)
make 2>&1 | tee build.log
make > build.log 2>&1
make -j 2 2>&1 | tee build.log
编译完成之后,进行安装
cd ANTS-build
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,出现以下错误:
[ 0%] Building CXX object Examples/CMakeFiles/antsUtilities.dir/antsUtilities.cxx.o
[ 1%] Building CXX object Examples/CMakeFiles/antsUtilities.dir/antsRegistrationTemplateHeader.cxx.o
In file included from /home/duzh/ANT/ANTs/Examples/antsRegistrationTemplateHeader.cxx:1:
/home/duzh/ANT/ANTs/Examples/antsRegistrationTemplateHeader.h:21:10: fatal error: itkLabelImageGenericInterpolateImageFunction.h: No such file or directory
21 | #include "itkLabelImageGenericInterpolateImageFunction.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[5]: *** [Examples/CMakeFiles/antsUtilities.dir/build.make:90: Examples/CMakeFiles/antsUtilities.dir/antsRegistrationTemplateHeader.cxx.o] Error 1
make[5]: *** Waiting for unfinished jobs....
make[4]: *** [CMakeFiles/Makefile2:2827: Examples/CMakeFiles/antsUtilities.dir/all] Error 2
make[3]: *** [Makefile:166: all] Error 2
make[2]: *** [CMakeFiles/ANTS.dir/build.make:88: ANTS-prefix/src/ANTS-stamp/ANTS-build] Error 2
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/ANTS.dir/all] Error 2
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
键编辑
export ANTSPATH=/home/duzh/ANT/antsbin/bin/
export PATH=${ANTSPATH}:$PATH
按Esc
,再按:wq
退出
保存修改source ~/.bash_profile
注意这个是你cmake的时候填写的CMAKE_INSTALL_PREFIX
对应的地址
默认是:
export ANTSPATH=/opt/ANTs/bin/
export PATH=${ANTSPATH}:$PATH
五、检测是否成功安装
which antsRegistration
antsRegistrationSyN.sh
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