Image registration with bUnwarp - Macro

Hello ImageJ community (and Ignacio),

I am implementing a (Matlab) pipeline for non-linear registration of high res brain histology (and other) slices. The tool bUnwarpJ is our target for this as we want to combine landmark-based and image-based features. I am going to put up a dev pipeline and a production pipeline. First question about the dev pipeline :slight_smile:

High level structure of the dev pipeline:

  1. Pre-process source and target images
  2. Call bUnwarp -align to estimate the transformations (direct and inverse)
  3. Call bUnwarp -elastic_transform to apply the direct transformation to the source image and additional images in the same space as the source image and save the warped source and warped additional images.
  4. Extract image similarity between warped source and target
  5. Loop step 2/ to step 4/ with different parameters and/or landmarks

Here are some questions about this pipeline :
Step1/ and 2/ works fine.
Step3/ to validate this step 3, I ran the following very simple command as ImageJ Macro:

trTxt = "C:"+File.separator+"data"+File.separator+"histology"+File.separator+"warpWork"+File.separator+"ppMRISlices"+File.separator +"wR602_s170_BDA_NR_10x__direct_transf.txt"
run("bUnwarpJ","-elastic_transform target.png moving.png "+ trTxt +" output.tif"); 

This is not working: here is the error message

(Fiji Is Just) ImageJ 2.0.0-rc-59/1.51j; Java 1.8.0_66 [64-bit]; Windows 7 6.1; 41MB of 24452MB (<1%)
	at bunwarpj.PointToolbar.<init>(
	at bunwarpj.MainDialog.<init>(
	at ij.IJ.runUserPlugIn(
	at ij.IJ.runPlugIn(
	at ij.Executer.runCommand(
	at ij.macro.Functions.doRun(
	at ij.macro.Functions.doFunction(
	at ij.macro.Interpreter.doStatement(
	at ij.macro.Interpreter.doStatements(
	at ij.plugin.Macro_Runner.runMacro(
	at ij.IJ.runMacro(
	at ij.IJ.runMacro(
	at net.imagej.legacy.IJ1Helper$
	at net.imagej.legacy.IJ1Helper$
	at net.imagej.legacy.IJ1Helper.runMacroFriendly(
	at net.imagej.legacy.IJ1Helper.runMacro(
	at net.imagej.legacy.plugin.IJ1MacroEngine.eval(
	at net.imagej.legacy.plugin.IJ1MacroEngine.eval(
	at org.scijava.thread.DefaultThreadService$
	at java.util.concurrent.ThreadPoolExecutor.runWorker(
	at java.util.concurrent.ThreadPoolExecutor$

Step 4/ What would be the macro call for “Evaluate Image Similarity” that gives back an image similarity metric ?

Thanks in advance


Hello @ChrCoello and welcome to the ImageJ forum!

I think you get confused between the macro call and the command line call. As explained in the documentation, your macro call should be something like this:

target = "C:"+File.separator+"data"+File.separator+"histology"+File.separator+"warpWork"+File.separator+"tmpVol"+File.separator+"target.png";
moving = "C:"+File.separator+"data"+File.separator+"histology"+File.separator+"warpWork"+File.separator+"tmpVol"+File.separator+"moving.png";
call( "bunwarpj.bUnwarpJ_.elasticTransformImageMacro", target, moving, trTx, "output.tif" ); 

Sorry, that method is not callable from a macro. I should work on it… In the mean time, you can simply calculate the mean square error of the pixel intensities between your target and transformed images. How does it sound?


1 Like

Thanks a lot for your answer Ignacio.
Sorry for the confusion between macro and command call, that is due to my complete ignorance of Fiji. Your macro call works fine, thanks.
Yes, no problem. I have implemented the image similarity metric and will use this for now. I was just being lazy. No need (at least for me) to work on it.


Thanks for letting me know, Christopher. I’m already working on a better (easier) macro use :wink:

Thanks @iarganda.
A little follow-up on this. I have seen in the documentation ( that the results are in 32 bits which is fine. But I have not seen/found in there if we could select an interpolation method that keeps the values of the original image (often nearest neighbour). Typically in the case when you calculate the warp with one image modality, and apply it to an associated image label (discrete set of values).
You can see the original histogram (left) and the histogram after warping (right) of the label image below

I know this is a very uncommon case (more common in the in-vivo MRI/PET world) and would understand it is not covered here.



You are right, there is no option in bUnwarpJ to select the interpolation method. I can add it to my TODO list.

You can try using Register Virtual Stack Slices, which allows you to perform elastic registration using bUnwarpJ and two types of interpolation (“none” or bilinear), but the registration is only based on the automatically detected landmarks…

Just a quick update to this topic: since version 2.6.7, bUnwarpJ is completely macro compatible, which means all I/O functions are now callable from macro.

As usual, the easiest way to know how to make the calls is using the Macro Recorder.

Any feedback about usability, bugs or new features is welcome!