BigWarp and Macro Usage

Hi,

I wrote a macro that does the following:

  1. Ask the user to select and open two images (i.e., “SegImage” and “ExpImage”)
  2. Call the plugin BigWarp and load the two images previously open.

After this, my guess is that because we need to specify landmark points (and the number of points can change depending on the image and the level of accuracy needed in the warping operation), we need to proceed interactively. Can anyone confirm this?

In addition, I would like to add a third step to the macro: saving the warped image. For that, I’m considering the following:

MorphChoice = getBoolean("Did you complete morphing the segmented image??"); 

while(MorphChoice==0){
    MorphChoice = getBoolean("Did you complete morphing the segmented image??"); 
}

OutputFolder = getDirectory("Select where to save the output image");
selectWindow(SegImageName+"_"+SegImageName+"_xfm_0")
saveAs("Tiff", OutputFolder + ExpImageName + "_Morphed");

This dialog box should appear after I manually perform the warping and close BigWarp. The problem is that the dialog box always stays on top of everything and does not let me even use BigWarp unless I provide input to the dialog box. For your reference, the whole macro is attached below:

Thanks,
JR

Whole macro:

//Get experimental image
ExpImagePath = File.openDialog("Select the experimental image");
ExpImageFolder = File.getParent(ExpImagePath);
ExpImageName = File.getName(ExpImagePath);
print("The folder of the experimental image is: " + ExpImageFolder);
print("Experimental image name/title is: " + ExpImageName);

open(ExpImagePath);
ExpImageID=getImageID();
ExpImageWidth=getWidth();
ExpImageHeight=getHeight();
print("Experimental image ID is: " + ExpImageID);
print("Experimental image height (pixels): " + ExpImageHeight);
print("Experimental image width (pixels): " + ExpImageWidth);
print("--------------------------------------");

//Get segmented image
SegImagePath = File.openDialog("Select the segmented image");
SegImageFolder = File.getParent(SegImagePath);
SegImageName = File.getName(SegImagePath);
print("The folder of the segmented image is: " + SegImageFolder);
print("Segmented image name/title is: " + SegImageName);

open(SegImagePath);
SegImageID=getImageID();
SegImageWidth=getWidth();
SegImageHeight=getHeight();
print("Segmented image ID is: " + SegImageID);
print("Segmented image height (pixels): " + SegImageHeight);
print("Segmented image width (pixels): " + SegImageWidth);
print("--------------------------------------");

print("--------------------------------------");
print("Segmented Image: " + SegImageName);
print("Experimental Image: " + ExpImageName);

//Run morphing (BigWarp) command
run("Big Warp", "moving_image=SegImageName target_image=ExpImageName");

//After running the BigWarp command, everything needs to be done interactively
//However, we can automate the saving of the generated (morphed) image
//Confirm the completion of morphing

MorphChoice = getBoolean("Did you complete morphing the segmented image??");

while(MorphChoice==0){
    MorphChoice = getBoolean("Did you complete morphing the segmented image??"); //1=TRUE/YES; 0=FALSE/NO
}

OutputFolder = getDirectory("Select where to save the output image");
selectWindow(SegImageName+"_"+SegImageName+"_xfm_0")
saveAs("Tiff", OutputFolder + ExpImageName + "_Morphed");

Hey @jerr,

you’re right, BigWarp might be to complex for macro scripting…

Instead of this code snippet, give this a try:

waitForUser("Done?");

https://imagej.nih.gov/ij/developer/macro/functions.html#waitForUser

Let us know if that works!

Cheers,
Robert

1 Like

Hi @haesleinhuepf,

Thanks for your help. Adding that snippet worked. I would prefer having a command that waits for the user input and proceeds based on the user input. However, your suggestion will suffice for me in the meantime. Thanks!.

By the way, do you know of an alternative to close BigWarp? I tried the command close() and run("Close"), but they didn’t work and I still have the Bigwarp moving image, Bigwarp fixed image, and Landmarks windows open. I also tried, for example, close(Landmarks), but it also didn’t work.

Regards

JR

Hi JR (@jerr)

I could help you with programmatically closing Bigwarp if you were using groovy/java/jython, but I’m not sure how to do it with an imagej macro.

John

P.S. I’m not even sure it’s possible with an imagej macro. afaik, one can only call static java methods from an imagej macro. ij-macro experts - Is that right?

1 Like

More or less, yes. However, if anyone likes to program some macro-extensions with auto-completion for BigWarp, I’d be happy to assist :wink:

Let me know!

Cheers,
Robert

1 Like

Hi @bogovicj ,

Sure. I would appreciate it if you can show me how to programmatically close Bigwarp using Java.

Regards,
JR

1 Like

Hi JR (@jerr),

Here’s some code that opens bigwarp starting with two ImagePlus's, waits 3 seconds, then closes bigwarp. This code should work using either Java or groovy.

ImagePlus movingImg = ...
ImagePlus fixedImg = ...

BigWarp bw;
try
{

   // start bigwarp
    bw = new BigWarp( 
    	BigWarpInit.createBigWarpDataFromImages( movingImg, fixedImg ),
    	"bigwarp", null );
}
catch(Exception e){}

// wait a few seconds to prove bigwarp is really open
Thread.sleep(3000);

// close bigwarp
bw.closeAll()
1 Like