Orientation in batch processing?

Hello everyone,

I’ve hit a bit of a snag with BoneJ that I hoped someone might be able to help with (I’m new to the program myself).

I’d like to do batch processing on a large number of scanned cross-sections (old school–these are traced from physical casts and then scanned, so no internal geometry). They are already oriented (they match the default orientation settings in ImageJ). Slice geometry works great in batch mode, but I can’t get batch mode to work when I add the Orientation plugin and I need the extra information that it provides.

Is there a way to either add the Orientation plugin to the macro or specify the orientations in the macro (since they are known) in a way that Slice Geometry will recognize?

Below I’ve pasted my crack at it–when it gets to run("Orientation"), an exception window pops up.

Many thanks!

-Gina

dir1 = getDirectory("Choose Source Directory ");
list = getFileList(dir1);

setBatchMode(true);

for (i=0; i<list.length; i++) {
     showProgress(i+1, list.length);
     open(dir1+list[i]);
     title = getTitle();

run("8-bit");

run("Properties...", "unit=mm pixel_width=0.04152 pixel_height=0.04152 voxel_depth=1");

run("Orientation");

run("Slice Geometry", "bone=unknown 2d_thickness draw_axes draw_centroids annotated_copy_(2d) bone_min=70 bone_max=255 slope=0.0000 y_intercept=1.8000");

close();
1 Like

Hello Gina,

Could you paste the exception you encounter here, please?

Regards,
Richard

Sure–here’s the text from the window (the exception has no specific error number):

ImageJ 1.49v; Java 1.6.0_24 [64-bit]; Windows NT (unknown) 6.2; 21MB of 12242MB (<1%)
 
java.lang.NullPointerException
	at org.doube.geometry.Orienteer.addLabels(Orienteer.java:506)
	at org.doube.geometry.Orienteer.rotate(Orienteer.java:485)
	at org.doube.geometry.Orienteer.rotateTo(Orienteer.java:499)
	at org.doube.geometry.Orienteer.setup(Orienteer.java:269)
	at org.doube.geometry.Orienteer.<init>(Orienteer.java:239)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at java.lang.Class.newInstance0(Class.java:355)
	at java.lang.Class.newInstance(Class.java:308)
	at ij.IJ.runUserPlugIn(IJ.java:197)
	at ij.IJ.runPlugIn(IJ.java:163)
	at ij.Executer.runCommand(Executer.java:132)
	at ij.Executer.run(Executer.java:65)
	at ij.IJ.run(IJ.java:279)
	at ij.IJ.run(IJ.java:254)
	at ij.macro.Functions.doRun(Functions.java:602)
	at ij.macro.Functions.doFunction(Functions.java:95)
	at ij.macro.Interpreter.doStatement(Interpreter.java:227)
	at ij.macro.Interpreter.doBlock(Interpreter.java:605)
	at ij.macro.Interpreter.doStatement(Interpreter.java:269)
	at ij.macro.Interpreter.doFor(Interpreter.java:527)
	at ij.macro.Interpreter.doStatement(Interpreter.java:251)
	at ij.macro.Interpreter.doStatements(Interpreter.java:215)
	at ij.macro.Interpreter.run(Interpreter.java:112)
	at ij.macro.Interpreter.run(Interpreter.java:82)
	at ij.macro.Interpreter.runBatchMacro(Interpreter.java:152)
	at ij.plugin.BatchProcessor.runMacro(BatchProcessor.java:218)
	at ij.plugin.BatchProcessor.run(BatchProcessor.java:412)
	at java.lang.Thread.run(Thread.java:662)

Hi Gina,

Thanks for this. Orientation was designed with user interaction in mind, so it lacks a few of the features of macro recordability. Your question is timely though because Richard and I have been fixing lots of exceptions in it on BoneJ’s testing branch.

You could try opening Orientation manually at the beginning of the session and setting the direction that you want on an image that you open. Then run your macro without the setBatchMode(true); and run("Orientation"); lines).

Also you need to tell Slice Geometry to use orientation in the macro; at the moment that means to include the word use in the run() call, like so:

run("Slice Geometry", "bone=unknown 2d_thickness draw_axes draw_centroids annotated_copy_(2d) use bone_min=70 bone_max=255 slope=0.0000 y_intercept=1.8000");

Future version of Slice Geometry will record use_orientation instead of use for macros.

1 Like

Hi again Gina,

I think I got your macro working with the following changes:

dir1 = getDirectory("Choose Source Directory ");
list = getFileList(dir1);

for (i=0; i < list.length; i++) {
    showProgress(i+1, list.length);
    open(dir1+list[i]);
    run("8-bit");
    run("Properties...", "unit=mm pixel_width=0.04152 pixel_height=0.04152 voxel_depth=1");
    run("Orientation");
    run("Slice Geometry", "bone=unknown 2d_thickness draw_axes draw_centroids annotated_copy_(2d) use bone_min=70 bone_max=255 slope=0.0000 y_intercept=1.8000");
}

Like @mdoube mentioned, the plugin doesn’t work in batch mode yet, so I dropped the setBatchMode line.
The script above leaves all the images visible after processing the directory. There’s bug in the Orientation plugin which makes it crash sometimes when images are closed. This means that you can’t call the close() function in the macro. @mdoube I think the bug reported in (issue #18) covers this case as well.

Regards,
Richard

2 Likes

Hello again,

Thank you both for your help.

I had a chance to try each method and both work. Richard’s solution works smoothly on its own, and Michael’s suggestion works so long as I click the “Orientation” window (make that window active) immediately after ImageJ opens the next image in the sequence, otherwise I get the exception pasted below (it may be identical to the one prior). I share this only in case it might be helpful as you mentioned you are working with Orientation.

Thank you for making my life (infinitely) easier over the new few months!

-Gina

Exception:

ImageJ 1.49v; Java 1.6.0_24 [64-bit]; Windows NT (unknown) 6.2; 77MB of 12242MB (<1%)
 
java.lang.NullPointerException
	at org.doube.bonej.SliceGeometry.run(SliceGeometry.java:345)
	at ij.IJ.runUserPlugIn(IJ.java:199)
	at ij.IJ.runPlugIn(IJ.java:163)
	at ij.Executer.runCommand(Executer.java:132)
	at ij.Executer.run(Executer.java:65)
	at ij.IJ.run(IJ.java:279)
	at ij.macro.Functions.doRun(Functions.java:600)
	at ij.macro.Functions.doFunction(Functions.java:95)
	at ij.macro.Interpreter.doStatement(Interpreter.java:227)
	at ij.macro.Interpreter.doBlock(Interpreter.java:605)
	at ij.macro.Interpreter.doStatement(Interpreter.java:269)
	at ij.macro.Interpreter.doFor(Interpreter.java:527)
	at ij.macro.Interpreter.doStatement(Interpreter.java:251)
	at ij.macro.Interpreter.doStatements(Interpreter.java:215)
	at ij.macro.Interpreter.runMacro(Interpreter.java:138)
	at ij.macro.MacroRunner.run(MacroRunner.java:152)
	at java.lang.Thread.run(Thread.java:662)
1 Like

Hi @Gina,

Thanks for the bug reports. We’ve incorporated fixes which should be available to you on the next BoneJ release. That should make your experience a bit more stable. In the meantime, just use @rimadoma’s suggested macro because it is working for you.

Michael

1 Like