# SimpleITK - connecting to other image processing libraries

**URL:** https://discourse.itk.org/t/simpleitk-connecting-to-other-image-processing-libraries/3491
**Category:** Engineering
**Tags:** simpleitk
**Created:** [September 29, 2020, 9:26am UTC](https://discourse.itk.org/t/simpleitk-connecting-to-other-image-processing-libraries/3491 "2020-09-29T09:26:35Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![haesleinhuepf](https://discourse.itk.org/user_avatar/discourse.itk.org/haesleinhuepf/32/977_2.png) [@haesleinhuepf](https://discourse.itk.org/u/haesleinhuepf)
#### Post date: [September 29, 2020, 9:26am UTC](https://discourse.itk.org/t/simpleitk-connecting-to-other-image-processing-libraries/3491/1 "2020-09-29T09:26:35Z")

</div>

Hey all,  
@blowekamp @matt.mccormick

first of all congrats to the developers for the SimpleITK 2.0 release! 🥳

I was just exploring it from Java and I’m wondering how to pipe pixels from another source into an ITK image. I do have various options for accessing pixels from our side but I can’t see a way for creating an ITK Image from them.

In my typical workflows, images exist as [JNI](https://de.wikipedia.org/wiki/Java_Native_Interface) Buffer, that’s an array allocated in a native C++ library, and Java has only a pointer to it. I could copy over that array in a Java float[] array (which appears a de-tour). Furthermore, I could offer the image encapsulated in various ImageJ objects. But that boils down to arrays of arrays of type float for example.

Is there a code example showing how to create a Simple ITK image from a Java float[] array or a JNI pointer and given dimensions? The opposite direction would be interesting as well. btw. 🙂

Thanks in advance!

Cheers,  
Robert

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [September 29, 2020, 1:30pm UTC](https://discourse.itk.org/t/simpleitk-connecting-to-other-image-processing-libraries/3491/2 "2020-09-29T13:30:26Z")

</div>

Hello @haesleinhuepf,

To create a SimpleITK image from a buffer, use the [ImportImageFilter](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1ImportImageFilter.html#details), don’t forget to set the origin/spacing/direction cosine.

To get the image buffer back use the [Image’s](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1Image.html) `GetBufferAsXYZ` methods.

---

<div class="post-metadata">

### Author: ![haesleinhuepf](https://discourse.itk.org/user_avatar/discourse.itk.org/haesleinhuepf/32/977_2.png) [@haesleinhuepf](https://discourse.itk.org/u/haesleinhuepf)
#### Post date: [September 29, 2020, 5:22pm UTC](https://discourse.itk.org/t/simpleitk-connecting-to-other-image-processing-libraries/3491/3 "2020-09-29T17:22:31Z")

</div>

Hey @zivy,

thanks for the hints! Unfortunately, the Java API doesn’t expose these methods:  
 ![image](https://discourse.itk.org/uploads/default/original/2X/1/1a44951b8dc4e011d8a786ff01e65f2a0525017b.png)

![image](https://discourse.itk.org/uploads/default/original/2X/e/ed57495b5d04932f868117c0f01aaff648498edc.png)

Are you sure they are part of SimpleITK 2.0.0?

In case that’s helpful, my full code lives [here](https://github.com/clij/clijx-assistant-simpleitk/blob/master/src/main/java/net/haesleinhuepf/clijx/simpleitk/CLIJSimpleITKUtilities.java#L18).

Thanks!

Cheers,  
Robert

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [September 29, 2020, 6:01pm UTC](https://discourse.itk.org/t/simpleitk-connecting-to-other-image-processing-libraries/3491/4 "2020-09-29T18:01:32Z")

</div>

You are correct. The `ImportImageFilter` is not available for the Java interface ( nor any other wrapped language ) due to expose of raw buffer pointers.

The [CSharpIntegration](https://simpleitk.readthedocs.io/en/master/link_CSharp_docs.html) example may be of some use to figure out how to copy the buffer in Java.

Contributions to improve the documentation and efficiency of the interface is certainly welcome 🙂

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [September 29, 2020, 6:10pm UTC](https://discourse.itk.org/t/simpleitk-connecting-to-other-image-processing-libraries/3491/5 "2020-09-29T18:10:53Z")

</div>

Please create feature request as a [Github Issue](https://github.com/SimpleITK/SimpleITK/issues) so that we can determine what needs to be done to fix and improve the interface to enable this.

---

<div class="post-metadata">

### Author: ![haesleinhuepf](https://discourse.itk.org/user_avatar/discourse.itk.org/haesleinhuepf/32/977_2.png) [@haesleinhuepf](https://discourse.itk.org/u/haesleinhuepf)
#### Post date: [September 29, 2020, 6:22pm UTC](https://discourse.itk.org/t/simpleitk-connecting-to-other-image-processing-libraries/3491/6 "2020-09-29T18:22:14Z")

</div>

Alright, I did so.

> <https://github.com/SimpleITK/SimpleITK/issues/1215>
>
> Hi all,
> it appears that the interface for generating an Image from a JNI buffer (e.g. FloatBuffer) is not available.
> Similarily, also image.getBufferAsFloat()...

Thanks for taking a look into this and let me know if I can help!
