Skip to content

ubuntu下安装ITK

操作环境

  • vmware 10
  • ubuntu-14.04.2-desktop-amd64

具体操作

安装Cmake

  1. 安装curses库,这个库可以让cmake运行成GUI界面,生成ccmake
shell
sudo apt-get install libncurses5-dev
sudo apt-get install cmake-curses-gui
  1. 安装cmake,这里一定要手动选择安装3.7.0的cmake,而不是apt-get install,否则会是问题很多的2.8.12
shell
cd /home/bwb #进入你自己的目录
wget "https://cmake.org/files/v3.7/cmake-3.7.0.tar.gz"
tar zxvf cmake-3.7.0.tar.gz
cd cmake-3.7.0
sudo su #一定要加这句话root,否则下面语句会没有权限
./bootstrap && make && make install
  1. 验证安装
shell
cmake --version
ccmake --version

安装编译ITK

  1. 下载4.10.1版本的ITK,需要自己用浏览器下载,因为并不是文件地址,而是一个下载服务的网页:https://sourceforge.net/projects/itk/files/itk/4.10/InsightToolkit-4.10.1.tar.gz/download。下载文件InsightToolkit-4.10.1.tar.gz放入/home/bwb

  2. 建立目录,解压

shell
cd /home/bwb
mkdir ITK
mkdir ITK/build
tar -zxvf ../InsightToolkit-4.10.1.tar.gz #把/home/bwb下的压缩文件解压到/home/bwb/ITK里
  1. 编译
shell
cd /home/bwb/ITK/build
ccmake ../InsightToolkit-4.10.1
  1. 出现了GUI界面,按c键配置。然后会提示一些设置,但其实根本不用设置,注意下这两个选项是不是OFF就行,不是OFF改成OFF:
shell
BUILD_EXAMPLES  *OFF
BUILD_TESTING   *OFF

更改的方法是,光标上下选择,回车修改,回车保存

  1. 继续按c键配置,提示成功,然后按g生成编译文件。
  2. make
shell
make

测试ITK

建立目录

shell
cd /home/bids/ITK
mkdir test       //工程文件
mkdir test/src   //存放源代码
mkdir test/bin    //示例编译目标
mkdir test/src/HelloWorld //项目名称
mkdir test/bin/HelloWorld //项目名称

拷贝官方的HelloWorld程序

shell
cp /home/bwb/ITK/InsightToolkit-4.10.1/Examples/Installation/* /home/bwb/ITK/test/src/HelloWorld

会有两个文件:CMakeLists.txtHelloWorld.cxx

进入bin目录,编译src的文件

shell
cd /home/bwb/test/bin/HelloWorld
ccmake /home/bwb/ITK/test/src/HelloWorld

可能会出现错误:

shell
ITK_DIR_NOTFOUND

同样用箭头上下选择,回车修改保存,改为ITK的目录:

shell
/home/bwb/ITK/build

重新按c配置,按g生成编译文件

make

shell
make   # 生成 HelloWorld 可执行文件
./HelloWrold  # 执行

e7003d7533c8154204c395532a1b2eea.png 最终结果:

text
ITK Hello World!

Helloworld的CMakeList.txt解释

text
#最低cmake版本要求
cmake_minimum_required(VERSION 2.8.9)
 
if(COMMAND CMAKE_POLICY)
  cmake_policy(SET CMP0003 NEW)
endif()
 
#项目名称
project(HelloWorld)
 
#ITK依赖的包的路径,include进来
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
 
#把HelloWorld.cxx源文件编译成HelloWorld可执行程序
add_executable(HelloWorld HelloWorld.cxx )
 
#指定编译参数
target_link_libraries(HelloWorld ${ITK_LIBRARIES})

安装过程中出现的坑

1. 出现undefined reference to symbol 'pthread_create'

明显是多线程模块没有正确加载。检查一下ubuntu有没有安装pthread:

shell
bwb@ubuntu:~$ man -k pthread_create
pthread_create (3)   - create a new thread

安装了的,如果没有安装则安装:

shell
sudo apt-get install glibc-doc
sudo apt-get install manpages-posix-dev

修改了一下CMakeLists.txt:

text
target_link_libraries(HelloWorld ${ITK_LIBRARIES})
改为
target_link_libraries(HelloWorld ${ITK_LIBRARIES} -lpthread)

解决了。

2. 报错undefined reference to 'itksys::SystemTools....'

857f6171101de1168c3f0b8379b802a7.png 没有相关的资料,唯一在google查到的资料是一段邮件对话
他说问题在cmake:

text
These messages indicate possible issues with the CMake configuration.
 
For more information, see the "Configuring and Building ITK" section
of the ITK Software Guide:
 
  https://itk.org/ITKSoftwareGuide/html/Book1/ITKSoftwareGuide-Book1ch2.html#x22-130002
 
and find a downloadable HelloWorld example that includes the CMake
configuration here:
 
  https://itk.org/ITKExamples/src/Core/Common/BuildAHelloWorldProgram/Documentation.html
 
Hope this helps,
Matt

我用的2.8.12,是ITK最新版本的最低要求,所以我直接换用更高版本cmake和更低版本ITK了,才解决了,否则怎么改makefile文件都会报这个错。

参考资料

ITK配准分割简明教程

  • 终于找到了一本用ITK进行配准和分割的入门教程《(ITK实现 全2册)》,还是咱大成电出版的哦,写得非常详细,入门很有帮助。
  • ITK官方的代码例子解释,不过是全英文的,稍微入门后可以继续看这个深入。
转载请注明出处https://bananaoven.com/articles/184.html | 香蕉微波炉
分享许可方式知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议
重大发现:转载注明原文网址的同学刚买了彩票就中奖,刚写完代码就跑通,刚转身就遇到了真爱。