Image registration in Java with ITK



Thanks @imagejan

Still very preliminary, but it’s a start (and seems to work in simple cases).


Would the above work better in:


I’m happy to shift development there (in a branch of my fork for now),
but maybe eventually merge into the main repo?

1 Like
  1. The SciJava conversion magic is crazy :slight_smile:
protected Image movingImage;
  1. I am not sure where the best place for this to live is. I feel it does make most sense where you put it right now, because then the kind of hairy dependencies in terms of the compiled libraries are guaranteed to be there when people install the imagej-itk update site.

Even more progress:

I wasn’t crazy about the fact that the repo as it is copies data, so started work on an in-memory imglib2 wrapper of itk images (accessible by SimpleITK).

Still early, but feedback most welcome.


Super interesting.

  1. I guess this is for the direction ITK => imglib2, right?
  2. I could not find the code for net.imglib2.img.itk.ItkImageImg is it in some of your repos?

How about:


Ok, looks like functions like this are the key:

public float getValue(int index)
	IntervalIndexer.indexToPositionForInterval(index, interval, position);
	return itkImage.getPixelAsFloat( position.getPosition() );

I think it is really very cool in imglib2 that on the java side we can essentially wrap everything into an image as long as we can somehow get the value of an individual pixel at the correct place!

Did you try if the performance of this is acceptable, e.g. to view images in bdv?

imglib2 to ITK

I was wondering about wrapping the other way around, i.e. imglib2 => ITK

I never used ITK but I looked a bit around and, to me, it looks like the concepts in ITK are super similar to imglib2, see for example this code (from

ImageType::Pointer im = GetAnImageSomeHow();
ImageIterator  it( im, im->GetRequestedRegion() );
while( !it.IsAtEnd() )
  it.Set( 10 );

This looks almost identical to what you would do imglib2. Thus, I am wondering, given someone on the ITK side would be interested, whether it would be possible to hand over some kind of a RandomAccessibleInterval to ITK where ITK would use the RandomAccess to retrieve the pixel values ( I guess, this would imply that the C++ side needs to make calls to methods on the Java side. I had a look whether something like this is possible and found this:
This is way above my head, but maybe someone more proficient could comment?

1 Like

Right—that would be one JNI call (from C++ into Java) per pixel. Horrible performance, unfortunately.

In order to make these integrations performant enough, data must be passed in blocks, not one pixel at a time. There are various solutions, but it takes some care. Or using shared memory, avoiding JNI calls for data access altogether.


A shame, it would be so cool!