Image Registration Suite

Tags: #<Tag:0x00007fd54766cc30> #<Tag:0x00007fd54766c9d8> #<Tag:0x00007fd54766c640> #<Tag:0x00007fd54766c280>


Hi All,

We are in the process of converting the Correct3D_Drift script to a proper Java plugin.

While doing so, in the new plugin we would like to give the user the option to chose via a drop-down menu between different image registration methods, such as

  • Translation_PhaseCorrelation (basically the Correct3D_Drift)
  • Translation_Elastix
  • Affine_Elastix
  • LocalDeformable_Elastix
  • a.s.o.

The user would have the choice to select a 5D reference region against which to register.

Also registrations could be saved, loaded and reapplied to other images.

Technically, we thought of just having a TransformationInterface and then above choices would be implementations of this interface; on top of this would be a SequenceRegistration class that would implement for instance logic to register a time lapse sequence.

We were wondering if that would be useful for the community and/or what would be additional/other suggestions regarding this.

Looking forward to reading your opinions!
Christian and Aliaksandr



This is awesome!

Please consider having your classes implement the imglib2 interfaces RealTransform or InvertibleRealTransform as applicable. This would make it much easier for some developers (cough, me) to take advantage of what you do…and you might find other stuff in that library useful as you work :smile:

btw, If you’re not already aware of it, the fiji-cmtk-gui will probably be of interest to you.

Looking forward to hearing more as you progress,


As a Correct3D_Drift user I have to say that this sounds great!
I would thoroughly enjoy having the possibility to choose between methods and to use Elastix based methods.

The ability to save and apply would add lots of power for me.
To expand on that, I could use an option of only applying xy and not z, and one for only z but not xy. I posted something similar to that here:

I could also use a registration tool that allows me to apply the same xy transform to all slices in a stack of different dimensions than the one in which the registration was originally calculated on.
An application example is: I ask the plugin to calculate the registration for the xy movement of my sample on a 2D maximum intensity projection of only one of the channels. Then I ask the plugin to apply the xy shifts to my original, multi-channel, 3D stack.
Another application example: Use the plugin to calculate the shift between channels based on images of fluorescent beads. Then apply the calculated shifts to a multi-channel xyzt stack.

Looking forward to using more of your progress,



I had a look at it and it seems that these interfaces are meant to work on single coordinate vectors; is that right? So far, we were rather thinking of an interface like this:

public void applyTransform( Image input, Image output );

…giving an image as an input and getting the whole transformed image as an output. But the approach you mention looks very interesting! Could you point us to example code where your suggestion is implemented and used to actually transform a whole image and display it? I have to admit here that we are not at all skilled in imglib2, but maybe this is the right moment to get into it!


We were entertaining the idea that the user could specify something like a registration axis; such that one could say whether one wants to register, e.g.

  • 2D-xy slices along z
  • 3D-xyz cubes along t
  • 3D-xyz cubes along c, i.e. align two channels with respect to each other.
  • a.s.o.

Does that sound like what you would like to have?


You are correct - that’s the “most low-level” interface. The code that transforms an image given a RealTransform is called RealTransformRandomAccessible, with convenience methods in RealViews.

Code would look like:

Img myImage = ...
RealTransform myTransform = ...
Img myTransformedImage = RealViews.transform( Views.interpolate( myImage, myIterpolator), myTransform);

where there’s a necessary interpolation step. (Later, I’ll put together some specific code that is actually runnable and post back)

There is not (as far as I know) an image-to-image interface as you describe, but anything that can transform images should also be able to transform points, and anything that can transform points can also transform images.



I have to admit this makes lots of sense!
I feel this might be the moment for me to finally embrace imglib2 :slight_smile:



I’ll be suuuuper happy to help if you run into roadblocks - I’d love an elastix wrapper/interface :smile:


Yes. It sounds very nice.


Thank you!

Are there already also interfaces, not for applying, but for finding the best transformation?

If not, would something like this make sense?

public RealTransform findTransform( RandomAccessibleInterval fixed, RandomAccessibleInterval moving )

As I said, I have hardly any clue about imglib2, but my idea would be that the RAI could be good because this could be a way to specify on which parts (intervals) of the two images the user wants to find the best transformation.


There is not such an interface in imglib2.

There is something like that in mpicbg: the Model interface, but it doesn’t operate on images, but rather on point correspondences, so not the same thing.

Yup, something like that looks good to me.



Here’s a beanshell script that builds a simple RealTransform (2d affine) and transforms and shows an image
using that transform.

It makes heavy use of convenience functions in the RealViews and Views classes.

import ij.IJ;
import net.imglib2.img.display.imagej.ImageJFunctions;
import net.imglib2.interpolation.randomaccess.NLinearInterpolatorFactory;
import net.imglib2.realtransform.*;
import net.imglib2.view.*;

img = ImageJFunctions.wrap( IJ.getImage());

AffineTransform2D xfm = new AffineTransform2D();
// rotate by some amount 
// note that the rotation is about the origin (0,0) in the top left of the image
xfm.rotate( Math.PI / 8 ); 
xfm.scale( 0.8 );  // scale by some amout

// real random accessible:
// extend: what are the values outside the image
// interpolate
// transform with the affine above
rra = RealViews.affine( 
    Views.interpolate( Views.extendZero( img ), new NLinearInterpolatorFactory() ),
	xfm );

// random accessible make it a raster image ,
// the same size as the original interval( _, interval)
ra = Views.interval( Views.raster( rra ), img ); ra );


Great! Works for me.
It looks like there still is this “bug” that the interpolator has trouble dealing with 255 in 8bit images:

        AffineTransform2D xfm = new AffineTransform2D();
		xfm.rotate(0.0 );
		xfm.translate(100.5, 100.0 );

		ExtendedRandomAccessibleInterval erai = Views.extendZero( img );
		RealRandomAccessible rra = Views.interpolate( erai, new NLinearInterpolatorFactory()  );
		AffineRandomAccessible ara = RealViews.affine( rra, xfm );

		RandomAccessibleInterval rai = Views.interval( Views.raster( ara ), img ); rai );


We have another question. In case we measure the drift sequentially, i.e. 1->2, 2->3, 3->4, a.s.o.; in order to apply the drift correction for time-point 4 we need to apply all the drifts to up this time-point (I hope this is understandable). I found below class, which does that, but I was a bit worried that this is maybe slow because, as I understand it, it has to for each pixel compute the combined transformation over and over again, isn’t it? If that’s true, is there some way to actually really “get” the combined transformation rather than recomputing it on the fly for every pixel?


I’ll look into that interpolation issue and report back.

You are correct that the RealTransformSequence will do what you describe. Whether you can “get” the whole transform depends on what it is. For Affine’s (and linear transforms) it’s easy: they all have concatenate and preConcatenate methods.

For (most, that I’m aware of) non-linear transforms, there’s not a straightforward way of concatenating one transform to another. It is possible to compose displacement fields, but to do it, you’d end up implementing RealTransformSequence, effectively. And, I don’t think there would be a speed improvement if you only visit each location once (unless I’m overlooking something).

On the plus side for speed: rendering transformed images is not hard to parallelize across space e.g. an undocumented example from BigWarp

@tpietzsch renders in parallel over several resolutions for bigdataviewer.



Yea, that nasty behaviour is due to overflows.
Its fixed by this ClampingNLinearInterpolator, but it lives in the bigdataviewer-core at the moment and hasn’t made it into imglib2-core yet.

(Edit: since Fiji has the bigdataviewer built in, you can just replace NLinearInterpolatorFactory with ClampingNLinearInterpolatorFactory in the script above and it’ll just work :slight_smile:)


I think this project is a great idea! I use Correct 3D drift a lot and all of the things mentioned in this thread would be really useful for me.


Hi All, @stelfrich @imagejan

During a very productive hackathon in Dresden I managed to create version 0.1.2 of the Image Registration Suite :slight_smile:

It obviously is super beta, but maybe you can give it a try and give me feedback, both regarding usability and code.

  • [Fiji > Update > Manage Update Sites > EMBL-CBA
  • Restart Fiji
  • [Fiji > Plugins > Registration > N-D Sequence Registration]

Feel free to post issues here:


@Christian_Tischer, sorry for being a noob, but it throws up an error (below) when trying to compute registration. What have I not got?

[INFO] ImageRegistrationPlugin started
[INFO] ## TransformationFinderRotationTranslationPhaseCorrelation
[INFO] ### TransformationFinderTranslationPhaseCorrelation
org.scijava.module.MethodCallException: Error executing method:
	at org.scijava.module.MethodRef.execute(
	at org.scijava.module.AbstractModuleItem.callback(
	at org.scijava.widget.DefaultWidgetModel.callback(
	at org.scijava.ui.swing.widget.SwingButtonWidget$1.actionPerformed(
	at javax.swing.AbstractButton.fireActionPerformed(
	at javax.swing.AbstractButton$Handler.actionPerformed(
	at javax.swing.DefaultButtonModel.fireActionPerformed(
	at javax.swing.DefaultButtonModel.setPressed(
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(
	at java.awt.Component.processMouseEvent(
	at javax.swing.JComponent.processMouseEvent(
	at java.awt.Component.processEvent(
	at java.awt.Container.processEvent(
	at java.awt.Component.dispatchEventImpl(
	at java.awt.Container.dispatchEventImpl(
	at java.awt.Component.dispatchEvent(
	at java.awt.LightweightDispatcher.retargetMouseEvent(
	at java.awt.LightweightDispatcher.processMouseEvent(
	at java.awt.LightweightDispatcher.dispatchEvent(
	at java.awt.Container.dispatchEventImpl(
	at java.awt.Window.dispatchEventImpl(
	at java.awt.Component.dispatchEvent(
	at java.awt.EventQueue.dispatchEventImpl(
	at java.awt.EventQueue.access$500(
	at java.awt.EventQueue$
	at java.awt.EventQueue$
	at Method)
	at java.awt.EventQueue$
	at java.awt.EventQueue$
	at Method)
	at java.awt.EventQueue.dispatchEvent(
	at java.awt.EventDispatchThread.pumpOneEventForFilters(
	at java.awt.EventDispatchThread.pumpEventsForFilter(
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(
	at java.awt.EventDispatchThread.pumpEvents(
	at java.awt.EventDispatchThread.pumpEvents(
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at org.scijava.module.MethodRef.execute(
	... 39 more
Caused by: java.lang.NoClassDefFoundError: net/imglib2/algorithm/phasecorrelation/PhaseCorrelation2
	... 44 more
Caused by: java.lang.ClassNotFoundException: net.imglib2.algorithm.phasecorrelation.PhaseCorrelation2
	at java.lang.ClassLoader.loadClass(
	at sun.misc.Launcher$AppClassLoader.loadClass(
	at java.lang.ClassLoader.loadClass(
	... 54 more


I don’t have that class in my up-to-date Fiji either.
A quick search on told me that it is contained in the net.preibisch::BigStitcher artifact.

@Christian_Tischer, your plugin apparently requires having the BigStitcher update site enabled as well, right?!