Friday, January 7, 2022

Install SimpleITK on Linux/Ubuntu for Java Application

In this tutorial, we are going to learn how to install SimpleITK which is very handy for medical image analysis.

SimpleITK is a simplified programming interface to the algorithms and data structures of the Insight Toolkit (ITK). It supports bindings for multiple programming languages including C++, Python, R, Java, C#, Lua, Ruby, and TCL. These bindings enable scientists to develop image analysis workflows in the programming language they are most familiar with. The toolkit supports more than 15 different image file formats, provides over 280 image analysis filters, and implements a unified interface to the ITK intensity-based registration framework. you can check out official documentation from here.

For the windows system, we can find the prebuilt library where we can simply download and install it. But for Linux os, we need to build by ourselves.


Download SimpleItk: 

Clone the SimpleITK from the github.  We can select the desired version from release and download or clone it.

git clone

Now change to the SimpleITK directory:

cd SimpleITK

Install Cmake:

sudo apt-get  install cmake
Install Java:
sudo apt install openjdk-8-jdk

Build SimpleITK

mkdir SimpleITK-build
cd SimpleITK-build
sudo cmake ../SuperBuild

The SuperBuild generates make files that take care of downloading and building ITK. Now start the build

make -j4

Note: Be careful not to run out of memory during the build. We need 4GB of memory per core. For example, if we compile with 4 cores (e.g. make -j4) we need a machine with at least 16GB of RAM.

It will take some time. After the installation, you can find the .so library file which we are going to use. Also, you can find the .jar file for java under the created build folder.

First, we need to load the ITK .jar file in our project and .so file by providing the JVM argument as
Where, /path/to/SimpleITKRuntime is the directory that contains the .so file. Otherwise, you will get the following error
Exception in thread "main" java.lang.UnsatisfiedLinkError: no SimpleITKJava in java.library.path
	at java.lang.ClassLoader.loadLibrary(
	at java.lang.Runtime.loadLibrary0(
	at java.lang.System.loadLibrary(
	at org.itk.simple.SimpleITKJNI.<clinit>(
	at org.itk.simple.SimpleITK.readImage(
	at simpleitk.SimpleItkTest.main(

Run the sample Java example

package simpleitk;

import org.itk.simple.Image;
import org.itk.simple.SimpleITK;

public class SimpleItkTest {
    public static void main(String[] args) {
		String inputImagePath = "/path/to/image";
		String outputImagePath = "/path/to/output/image";
        Image image = SimpleITK.readImage(inputImagePath);
        SimpleITK.writeImage(image, outputImagePath);

This is a sample example for reading and writing images using simpleITK library.

Note if we are using the Gradle project, then we can add the .so library path as below

bootRun {
Where, /opt/SimpleItk/ is the directory which contains the .so file.



Blog Archive