2009年4月1日星期三

[转]在ubuntu中使用ITK的方法

老外的文章,讲得很详细,方法很简单,但没有手册,就很麻烦。

Using ITK in Ubuntu GNU/Linux

http://www.robots.ox.ac.uk/~rcasero/wiki/index.php/Using_ITK_in_Ubuntu_GNU/Linux

Introduction

These are my notes as I learn how to use ITK in Ubuntu GNU/Linux, version 8.10 (Intrepid Ibex).

The Insight Segmentation and Registration Toolkit (ITK) is "an open-source, cross-platform system that provides developers with an extensive suite of software tools for image analysis".

Implementation details: "ITK is implemented in C++. ITK is cross-platform, using the CMake build environment to manage the configuration process. In addition, an automated wrapping process generates interfaces between C++ and interpreted programming languages such as Tcl, Java, and Python (using CableSwig)."

Licence: "ITK is copyrighted by the Insight Software Consortium, a non-profit alliance of organizations and individuals interested in supporting ITK. The software is distributed as open source under the OSI-approved BSD license."

Note that there's a closed source project also called ITK, and in the same field: Image Registration Toolkit (ITK). But these notes document the Insight Segmentation and Registration Toolkit, and that's what I'll refer to by ITK unless otherwise specified.

Resources:

Installation

Ubuntu has the following packages available:

$ sudo apt-get install cmake insighttoolkit3-examples libfftw3-dev libinsighttoolkit3-dev \
libinsighttoolkit3.6 python-insighttoolkit3 tcl8.4 tcl8.4-insighttoolkit3 \
tk8.4

ITK files are installed in

$ find /usr/ -iname "*insight*"
/usr/share/tcltk/tcl8.4/insighttoolkit3
/usr/share/doc/insighttoolkit3-examples
/usr/share/doc/libinsighttoolkit3.6
/usr/share/doc/libinsighttoolkit3.6/InsightLogo.gif
/usr/share/doc/tcl8.4-insighttoolkit3
/usr/share/doc/libinsighttoolkit3-dev
/usr/share/doc/libinsighttoolkit3-dev/InsightDeveloperStart.doc.gz
/usr/share/doc/libinsighttoolkit3-dev/InsightDeveloperStart.pdf.gz
/usr/share/doc/python-insighttoolkit3
/usr/share/python-support/python-insighttoolkit3
/usr/share/python-support/python-insighttoolkit3/InsightToolkit.py
/usr/share/man/man3/insighttoolkit.3.gz
/usr/share/lintian/overrides/libinsighttoolkit3.6
/usr/share/lintian/overrides/tcl8.4-insighttoolkit3
/usr/share/lintian/overrides/python-insighttoolkit3
/usr/include/InsightToolkit
/usr/lib/python-support/python-insighttoolkit3
/usr/lib/InsightToolkit

Probably the most interesting directory for the moment is the directory of the header files

$ ls /usr/include/InsightToolkit
Algorithms Common IO Numerics Utilities
BasicFilters gdcm itkConfigure.h SpatialObject

You also need to have a C++ compiler

$ sudo apt-get install g++

I was trying to compile some legacy code from Martin Bishop (i.e running 'make' after creating the Makefile with 'cmake'), and some libraries are required. I don't know whether this is a dependency of ITK in general, or Martin's code only. The libraries can be installed using (note that you need the development packages)

$ sudo apt-get install libpng12-dev libtiff4-dev

First example

The HelloWorld files of the example in section "2.1.1. Hello World!" of the ITK guide are in

$ ls /usr/share/doc/insighttoolkit3-examples/examples/Installation
CMakeLists.txt HelloWorld.cxx

Create a directory for the example and change directory to it

$ mkdir itk-helloworld
$ cd itk-helloworld

Copy the example files to your current directory

$ cp /usr/share/doc/insighttoolkit3-examples/examples/Installation/* .

Create a directory to generate the binaries and go to it

$ mkdir bin
$ cd bin

Now start CMake in order to create the Makefile

$ ccmake ..

This will show a console interface. Press 'c' to configure, and then 'g' to generate the Makefile. Now you should have

$ ls
CMakeCache.txt CMakeFiles cmake_install.cmake Makefile

Now compile the project

$ make
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as

cmake_minimum_required(VERSION 2.6)

should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.

-- Configuring done
-- Generating done
-- Build files have been written to: /home/ramc/secure_data/comlab/ramc/rcasero/software-projects/itk-helloworld/trunk/bin
Scanning dependencies of target HelloWorld
[100%] Building CXX object CMakeFiles/HelloWorld.dir/HelloWorld.o
Linking CXX executable HelloWorld
[100%] Built target HelloWorld

Now you should have

$ ls
CMakeCache.txt CMakeFiles cmake_install.cmake HelloWorld Makefile

(note the new binary HelloWorld). Run the binary to check that it works

$ ./HelloWorld
ITK Hello World !

没有评论:

发表评论