Automatically close a caution message window in a macro (BoneJ connectivity)

bonej
Tags: #<Tag:0x00007fb88991c6e0>

#1

Good evening,

I have a working macro which apply multiple calculations on a stack of images.

However, when it comes to measure the connectivity with the boneJ plugin, I’m in trouble because the connectivity is negative and a message pops up. I, the user, need to close that window so the macro can continue. The wish would be to make my macro user-independant.

1/ I could include a few code lines in the macro to close that message window but I don’t know how…

2/ I could go within the source code of the plugin (BoneJ) to remove those lines of code but I don’t neither know how to do that… How to implement it in the boneJ.jar file …

Can anyone help me with one of these solutions ?

Thank you in advance,

Best,

Sarah Smet
PhD student in hydropedology
ULg, Gx-ABT, Belgium


#2

Is your macro running in batch mode (setBatchMode(true))?

Please post the macro here if you are able.


#3

Hello Michael,

No it is not because it prevents from saving multiple windows from the calculations of one plugin.
It was previously running it with the Batch mode set to true but I couldn’t select and saveAs the window “Branch information” from analyze skeleton plugin or the plot from the fractal dimension calculation…

path1=getDirectory("Choose  a directory  for processing"); 
path2=getDirectory("Choose  a directory  for saving"); 
run("Image  Sequence...",  "open=path1"); setBatchMode(false); setOption("BlackBackground",  true); 
run("Make  Binary",  "method=Default  background=Dark  black"); 
vol_max=1000;
 for(i=10;i<vol_max;i=i+10)  { selectWindow("Min5voxels"); 
run("Gray  Scale  Attribute  Filtering  3D",  "operation=Opening  attribute=Volume  min="  +  i  +  " connectivity=26"); 
selectWindow("Min5voxels-attrFilt"); run("Connectivity"); 
selectWindow("Results"); 
saveAs("Results", path2  +  "Connectivity_"  +  i  +  ".csv");
 run("Close"); 
selectWindow("Min5voxels-attrFilt"); 
run("Fractal  Dimension"); 
selectWindow("Results"); 
saveAs("Results",  path2  +  "Fractal_"  +  i  +  ".csv");
 run("Close"); 
selectWindow("Min5voxels-attrFilt"); run("Anisotropy",  "auto  radius=2.5  vectors=50000  vector_sampling=2.300  min_spheres=100 max_spheres=2000  tolerance=0.0050"); 
selectWindow("Results");
 saveAs("Results", path2  +  "Anisotropy_"  +  i  +  ".csv"); 
run("Close"); 
selectWindow("Min5voxels-attrFilt"); run("Skeletonise  3D"); 
selectWindow("Skeleton  of  Min5voxels-attrFilt"); run("Analyse  Skeleton",  "prune=none  show"); saveAs("Results", path2  +  "Branch_info_"  +  i  +  ".csv"); 
run("Close"); 
selectWindow("Results"); 
saveAs("Results", path2  +  "Results_skel_"  +  i +  ".csv"); 
run("Close"); 
selectWindow("Tagged skeleton"); 
run("Close"); 
selectWindow("Skeleton  of  Min5voxels-attrFilt"); run("Close"); 
selectWindow("Min5voxels-attrFilt"); run("Analyze  Particles...",  "display"); 
selectWindow("Results"); 
saveAs("Results", path2  +  "Results_2D_"  +  i  +  ".csv");
 run("Close"); 
selectWindow("Min5voxels-attrFilt"); 
run("Close");  
 }

Sorry for the bad layout, I’m using my phone…


#4

Consider breaking your macro into different ones, so that the Results table doesn’t get clobbered by the different plugins, and so you can run Connectivity in batch mode.

It will mean you have to open and close all the images for each macro, but that will likely be faster than anything else (including fixing the BoneJ code).


#5

Running connectivity on batch mode will prevent the caution message from popping up?

Closing and opening again the images mean that I should save the stack resulting from the first operation (which is to remove particles smaller than a specified volume i) since I run the other plugin on those resulting stack of images. So I would have to save a couple hundreds times stacks of a thousand images… Or maybe I can delete them from ImageJ right after using it and before moving to the next “i”? Or maybe save them in a temporary folder?


#6

I’m not sure, please try it and report back here.

Something like that might be necessary, yes.


#7

You can include the following in your macro just before calling a plugin (see documentation):

IJ.redirectErrorMessages();

It is supposed to work with plugins that call IJ.error, though. I’m not sure if it also works with IJ.showMessage that the BoneJ plugin is using.


#8

I already tried but didn’t work…


#9

Didn’t work… I justem tried on one image, with only that plugin running (2 lines of code)

Isn’t it possible to select the window (“caution”) and close it while calling the plugin? Within the argument of the plugin.

I don’t see any other solution beside deleting those 3 lines of code on the source code of boneJ. But I don’t know how to do that… I don’t know if it is even possible?


#10

Yes it’s possible - I have a few minutes now so will see what I can do


#11

Try this testing version of BoneJ:

http://bonej.org/download/testing/BoneJ_.jar

You will need to include IJ.redirectErrorMessages(); in your macro.

The code change is here. I have not tested this change - it simply changes the IJ.showMessage() call to an IJ.error() call, which should make it susceptible to the macro workaround pointed out by @imagejan (thanks!).


#12

Thank you!!
I have updated IJ from v.1.49v to 1.5 since this version of boneJ wouldn’t work on IJ 1.49. There is however a java3d issue. The plugin “testJava3d” works well on IJ 1.49 but not on IJ 1.5 (neither is the connectivity plugin due to “java3D librairies not installed”). I have however installed the latest version of java3D. I’ve read some threads about that, where, you Michael were also writing about…
Any clue?
Best,

Sarah


#13

Sounds like you have hit the version creep issues we discussed at length last year. Your issue is unlikely to be due to the IJ version by itself, and more likely to be due to the Java version (or something else): did you update anything else, like, all of Fiji? For BoneJ1 I am still using vanilla ImageJ with 64-bit Java 1.6u45, with BoneJ_.jar and the old 3D viewer saved in the ImageJ/plugins/ directory. Running the 3D Viewer (as Administrator/sudo, if your Java is installed system-wide) will install Java3D 1.5.

Experience shows that it gets a bit hairy if you have a newish, updated Fiji ± Java 8 and try to run BoneJ1. The BoneJ2 project is intended to overcome these limitations, but we are quite a way from release at the moment.


#14

Indeed, I downloaded the latest version of ImageJ bundled with 64-bit Java 1.6.1_24 and I was able to run BoneJ.
I don’t use Fiji, it is not even installed on my computer.

However, when running a simple macro with the BoneJ release you sent

setBatchMode("false");
IJ.redirectErrorMessages();
run("Connectivity");

I get a log file and I can’t even click on “OK”, the only possibility is to close the window and I don’t get any result.

Caution: Connectivity is negative.

This usually happens if there are multiple
particles or enclosed cavities.

Try running Purify prior to Connectivity.

Isn’t possible to just remove those 3 lines of code? Just to not warn people that connectivity shouldn’t be negative?

I work in soil science, I study soil samples though X-ray microtomographic scans. It is not unusual to get positive Euler number (or negative connectivity)…

Best,

Sarah


#15

I’m loath to remove that warning because in trabecular bone, connectivity is always positive, otherwise something is seriously wrong. Users often don’t realise this and will just record whatever number the software spits out, regardless of whether it is a sensible or meaningful result.

What I could try is to suppress the warning whenever Connectivity is being called by a macro.

Try downloading the testing version again.


#16

Thank you Michael, it is now working on a simple macro. I have however an issue with the java version since MorphoLib apparenty need the Java 8 (Fiji Java Update) while I’m running on Java 6 as you advised me to do so (and which worked out for BoneJ!)…
So I guess I will have to split my macro in 2 différent one.

Sarah