The Insight Segmentation and Registration Toolkit (ITK) is a cross-platform, open-source framework that supports the development of image segmentation and registration applications with an extensive suite of software tools. This suite includes leading-edge algorithms for analyzing multidimensional data.
ITK is mainly implemented in C++, and it uses the CMake build environment to manage the process of generating and compiling projects in a platform-independent way. In addition, ITK can be wrapped for high-level programming languages such as Python with an integrated, automatic wrapping system. This system is based on Simplified Wrapper and Interface Generator (SWIG) for rapid prototyping and fast exploration.
Mingw-w64 is forked from the MinGW project. Mingw-w64 supports a complete run-time environment for the GNU Compiler Collection (GCC) on Windows 64-bit and 32-bit operating systems. Mingw-w64 also provides more complete Win32 application programming interfaces (APIs) including Windows 7/8/8.1 APIs, POSIX threads, and GCC multi-lib tool chains. Additionally, Mingw-w64 is used by several other projects such as Fedora MinGW, the R Project for Statistical Computing, and Qt. Consequently, Mingw-w64 compilers are widely applied.
Building ITK with Mingw-w64
In this blog post, we describe how to build ITK with the Mingw-w64 compiler.
Preparing Mingw-w64 compiler
The Mingw-w64 compiler can be download from the following Web page: http://mingw-w64.org/doku.php/download/mingw-builds.
Once you have clicked on “Sourceforge” in the webpage, the latest version installer of the Mingw-w64 compiler will automatically download.
After you have downloaded the installer of “mingw-w64-install.exe,” simply navigate to the download location on your computer, double-click the file, and press “Yes,” when the dialog box pops up.
Press “Next” to install the Mingw-w64 compiler on your Windows system.
Select i686 or x86_64 for the architecture; posix or Win32 for the threads; and dwarf, seh, or sjlj for the exception for installing the Mingw-w64 compiler. We recommend that you install the latest version of the Mingw-w64 64-bit (x86_64) compilers. Then, click “Next” to continue.
Define your destination folder for the Mingw-w64 compiler. Then, press “Next.”
You have completed the installation process; click “Finish.”
Now, you have a Mingw-w64 compiler on your Windows system.
Configuring and Building ITK with Mingw-w64 compiler
We will use CMake (the GUI version) and the Ninja build system for configuring and building ITK source code.
You can download a windows installer of CMake (cmake-X.X.X-win32-x86,msi) from the CMake download page. Follow the instructions provided on the CMake installation page for downloading and installing the software.
Note: Add CMake to the system path.
Preparing the Ninja Build System
The Ninja build system has been designed and developed for high speeds. CMake supports generating Ninja files on Windows, Linux, and Mac OS X.
Download the Ninja binary for Windows from the Ninja homepage, extract the zip file (ninja-win.zip), and copy the executable file in your destination folder. In our case, the path of the Ninja build system is “C:\Program Files\ninja-win.”
Then, add the destination folder of Ninja to the system path with the following steps:
- On the desktop, right-click on the computer icon.
- Choose “Properties” from the context menu.
- Click on the “Advanced System” settings link.
- Click “Environment Variables.”
- In the System Variables section, find the PATH environment variable, and select it.
- Click “Edit.”
- In the Edit System Variable window, insert the path of your Ninja directory.
- Click “OK.”
- Close all remaining windows by clicking “OK.”
Getting ITK Source Code
Configuring ITK with CMake and the Mingw-w64 Compiler
Open the terminal for the installed Mingw-w64 compiler by selecting “Run terminal.”
In the terminal, run “cmake-gui” to configure the ITK source code.
Define the path of the ITK source code and a binary directory in the respective “Where is the source code” and “Where to build the binaries” edit boxes. Then, press “Configure.”
If your binary directory does not exist, press “Yes” to create a folder.
Select “Ninja” as a generator to build the ITK source code.
For more information about configuring ITK, please see chapter 2.1 of “ITK Software Guide: Introduction and Development Guidelines.”
Once the configuration is done, press “Generate” to create Ninja files for compiling the ITK source code.
After the generation is complete, go to your binary directory in the terminal. Then, run the Ninja build system to compile the ITK source code.
Welcome to ITK! For more information about getting started with ITK, please check chapter 2.2 of “ITK Software Guide: Introduction and Development Guidelines.”