Image registration with bUnwarp - Macro

bunwarpj
Tags: #<Tag:0x00007fd541fa3520>

#1

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:

open("C:"+File.separator+"data"+File.separator+"histology"+File.separator+"warpWork"+File.separator+"tmpVol"+File.separator+"target.png")
open("C:"+File.separator+"data"+File.separator+"histology"+File.separator+"warpWork"+File.separator+"tmpVol"+File.separator+"moving.png")
trTxt = "C:"+File.separator+"data"+File.separator+"histology"+File.separator+"warpWork"+File.separator+"ppMRISlices"+File.separator +"wR602_s170_BDA_NR_10x__direct_transf.txt"
print(trTxt)
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%)
 
java.lang.NullPointerException
	at bunwarpj.PointToolbar.<init>(PointToolbar.java:126)
	at bunwarpj.MainDialog.<init>(MainDialog.java:126)
	at bunwarpj.bUnwarpJ_.run(bUnwarpJ_.java:133)
	at ij.IJ.runUserPlugIn(IJ.java:217)
	at ij.IJ.runPlugIn(IJ.java:181)
	at ij.Executer.runCommand(Executer.java:137)
	at ij.Executer.run(Executer.java:66)
	at ij.IJ.run(IJ.java:297)
	at ij.macro.Functions.doRun(Functions.java:601)
	at ij.macro.Functions.doFunction(Functions.java:96)
	at ij.macro.Interpreter.doStatement(Interpreter.java:230)
	at ij.macro.Interpreter.doStatements(Interpreter.java:218)
	at ij.macro.Interpreter.run(Interpreter.java:115)
	at ij.macro.Interpreter.run(Interpreter.java:85)
	at ij.macro.Interpreter.run(Interpreter.java:96)
	at ij.plugin.Macro_Runner.runMacro(Macro_Runner.java:155)
	at ij.IJ.runMacro(IJ.java:134)
	at ij.IJ.runMacro(IJ.java:123)
	at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1039)
	at net.imagej.legacy.IJ1Helper$3.call(IJ1Helper.java:1035)
	at net.imagej.legacy.IJ1Helper.runMacroFriendly(IJ1Helper.java:986)
	at net.imagej.legacy.IJ1Helper.runMacro(IJ1Helper.java:1035)
	at net.imagej.legacy.plugin.IJ1MacroEngine.eval(IJ1MacroEngine.java:97)
	at net.imagej.legacy.plugin.IJ1MacroEngine.eval(IJ1MacroEngine.java:144)
	at org.scijava.script.ScriptModule.run(ScriptModule.java:177)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)
	at org.scijava.thread.DefaultThreadService$2.call(DefaultThreadService.java:191)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

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

Thanks in advance

Christopher


#2

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?

Cheers!


#3

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.

Christopher


#4

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


#5

Thanks @iarganda.
A little follow-up on this. I have seen in the documentation (http://imagej.net/BUnwarpJ) 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.

Cheers,

Christopher


#6

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…


#7

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!