SimpleITK/GettingStarted/Visual guide to building on Linux
This guide gives detailed instructions for building SimpleITK on Linux. It is written for beginners getting started with SimpleITK.
Why Linux?
- Linux is freely available
- It has all the required tools
- Did I mention it's free?
Step 1: Get Linux
The first step is to install a Linux distribution. Some popular ones are:
And here is a comparison of those distributions.
There are many online tutorials explaining how to install your chosen Linux distribution:
- Ubuntu
- Mint
- Debian
If you are a Windows user, you may consider running Linux on a virtual machine. Some popular virtual machine environments are:
If you are a Mac OS X user, you can also run Linux in a virtual machine. Two virtual machine environments for OS X are:
Again, there are heaps of tutorials:
- Installing Ubuntu inside Windows using VirtualBox
- How to Install Ubuntu on VirtualBox
- Install Mint 16 on VirtualBox
- How to Install Linux Mint in Virtualbox (youtube)
This guide uses Debian 7, but the steps are very similar for other Linux distributions.
Step 2: Install build tools
The next step is to install the required build tools.
Open a terminal window (Application Menu > Terminal Emulator) and run the following command:
sudo apt-get install cmake cmake-curses-gui gcc g++ git
Confirm that you want to install the packages (press "y"), then wait for the installation to complete.
Alternatively, you could manually select each software package from the Synaptic Package Manager (Application Menu > Settings > Synaptic Package Manager).
By default building SimpleITK produces the SimpleITK C++ libraries and the SimpleITK Lua interpreter. It also supports bindings for other languages. To build this support, additional packages need to be installed. The following table shows the supported language bindings and the corresponding command to install the additional packages required for each language.
Programming Language | Command to install the build tools |
---|---|
C# | sudo apt-get install monodevelop |
Java | sudo apt-get install eclipse |
R | sudo apt-get install r-base r-base-dev |
Ruby | sudo apt-get install ruby |
Python | sudo apt-get install python python-dev |
Tcl | sudo apt-get install tcl tcl-dev tk tk-dev |
All languages | sudo apt-get install monodevelop eclipse r-base r-base-dev ruby python python-dev tcl tcl-dev tk tk-dev |
Step 3: Get SimpleITK source code
The next step is to get the SimpleITK source code using git.
Decide where you want to put the source code. I'm putting mine in my home directory:
cd ~
Now download the SimpleITK source code, by entering the following command in the Terminal:
git clone --recursive http://itk.org/SimpleITK.git
Now change to the SimpleITK directory:
cd SimpleITK
Step 4: Build SimpleITK
The next step is to start building.
The recommended way to build is via the so-called "super build". The build directory should not be inside the source tree. I put the build directory in the same directory as the source tree.
cd ~ mkdir SimpleITK-build cd SimpleITK-build cmake ../SimpleITK/SuperBuild
The SuperBuild generates make files which takes care of downloading and building ITK, SWIG, and Lua, as well as SimpleITK.
To start the (long) build process, type:
make
On my test system, a 4 core virtual machine with 16 GB of RAM, the build took just over an hour.
After the build is finished, you need to add SimpleITK to your LD_LIBRARY_PATH
:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/SimpleITK-build/lib
You can now (optionally) check whether the build was successful:
cd ~/SimpleITK-build ctest
All (or at least most) of the tests should pass.
Step 5: Use SimpleITK
A simple C# program
This section will describe how to create a simple C# application using SimpleITK from MonoDevelop.
Open MonoDevelop (Application Menu > Development > MonoDevelop).
Select File > New > Solution.
Select C# > Console Project. Enter a suitable name e.g. "sitk" and uncheck "Create directory for directory". Select "Forward" and then "OK".
In the Solution explorer, right-click "Selection" and select "Edit References...".
Select the ".Net Assembly" tab, navigate to "~/SimpleITK-build/SimpleITK-build/Wrapping/CSharpBinaries", select "SimpleITKCSharpManaged.dll", click "Add", and then close the window by selecting "OK". This will copy "SimpleITKCSharpManaged.dll" to your build directory e.g. "bin/Debug" or "bin/Release". You must also manually copy "libSimpleITKCSharpNative.so" to your build directories:
mkdir ~/sitk/bin/Debug mkdir ~/sitk/bin/Release cp ~/SimpleITK-build/SimpleITK-build/Wrapping/CSharpBinaries/libSimpleITKCSharpNative.so ~/sitk/bin/Debug cp ~/SimpleITK-build/SimpleITK-build/Wrapping/CSharpBinaries/libSimpleITKCSharpNative.so ~/sitk/bin/Release
SimpleITK has now been added as a project reference.
The following short program creates an image of a Gaussian blob, generates a derivative image from the Gaussian, scales and windows the derivative's intensities, converts the result to 8-bit unsigned ints, and writes out a PNG file:
using System; using sitk = itk.simple.SimpleITK; namespace SimpleITK { class MainClass { public static void Main (string[] args) { var size = new itk.simple.VectorUInt32( new uint[] {128, 128} ); var sigma = new itk.simple.VectorDouble( new Double[] {32.0, 32.0} ); var center = new itk.simple.VectorDouble( new Double[] {64.0, 64.0} ); var gauss = sitk.GaussianSource (itk.simple.PixelIDValueEnum.sitkFloat32, size, sigma, center); var deriv = sitk.Cast(128.0+24.0*sitk.Derivative (gauss), itk.simple.PixelIDValueEnum.sitkUInt8); sitk.WriteImage(deriv, "gauss-deriv-test.png"); } } }
To build the project press "F8" or select Build > Build All from the menu.
To debug the project, add a breakpoint at a desired location and press "F5".