BoneJ - Fractal Dimension and IJ Robot - how to automatically press "OK" on dialog box?

Hello ImageJ community,

I am writing a macro to calculate the Fractal Dimension of binary images of soil cores. I have a large number of image files to process (>> 1000) and will need to reuse this macro in the future.

When I run the macro, the call to Fractal Dimension results in a dialog box (“NB: Translations affect runtime significantly”) opening which requires “OK” to be pressed. This is required for every image to be processed. Given the large number of images I have this is not practical, as I result I want to have the macro automatically click “OK” for me.

After searching the forums and online help I have across the IJ Robot command which appears to do exactly what I want, enable the pressing of “OK” at a specified point on the screen. To work out the position of the “OK” button I followed the advice of G. Landini by obtaining a screengrab with the dialog box open, saving it as an image and then getting the coordinates of the image via ImageJ. I have tried numerous combinations of coordinates without success.

I was hoping someone may have advice on how to fix/work around this? I read another post on this forum about disabling the dialog box in the BoneJ source code but that is well beyond my coding skills.

The macro code is below.

Many thanks

Cameron
Brisbane, Queensland, Australia
PhD student (Soil Physics) - University of Southern Queensland

// 200622_folder_fractal_dimension.ijm
// DESCRIPTION. This script applies BoneJ command Fractal Dimension to all of the images in a file.
// The results are not saved as BoneJ does not allow you to do this. Must be done manually.

// initialisation. Input and output folders

run("Clear BoneJ results");

print("Running script: 200622_folder_fractal_dimension.ijm");
run("Options...", "iterations=1 count=1 black");

//image_dir = getDirectory("Select the Image Directory"); // select image folder
//print("Selected Image Directory is: " + image_dir);
image_dir = "C:\\Users\\lecko\\Documents\\1. PhD\\9. Research Papers\\JA3 - Calibration of image analysis methods\\Images\\bin_ori\\";

output_dir = "C:\\Users\\lecko\\Documents\\1. PhD\\9. Research Papers\\JA3 - Calibration of image analysis methods\\Images\\bin_ori\\";
//output_dir = getDirectory("Select the Output Directory"); // select output folder
//print("Selected Output Directory is: " + output_dir);

start_time = getTime();

// for loop that gets the list of files in the input folder and then calls Fractal Dimension
setBatchMode(true); // stops images from being opened on screen
list = getFileList(image_dir); // obtains all images in input folder

//for (i = 0; i < list.length; i++) // loops through each image in the folder and calls analyse particles.
for (i = 0; i < 1; i++) { // testing loop
	
	name = File.getName(list[i]); // captures the file name with extension
	print(name);
	fullName = image_dir + name;
	open(fullName); // opens the file
	run("Fractal dimension", "inputimage=net.imagej.ImgPlus@395a32b8 startboxsize=166 smallestboxsize=6 scalefactor=1.2 translations=0 autoparam=false showpoints=false");
	wait(1000);
	run("IJ Robot", "order=Left_Click x_point=916 y_point=583 delay=300 keypress=!");

	// Location of OK button from screen grab
	// 920, 581  918, 584
	// TL 906, 573. TR 926, 572, BL 906, 593, BR, 928, 596.
	// TOP 573. BOTTOM 593. LEFT 906. RIGHT. 926.
	// MIDDLE X = 916. CENTRE Y = 583.
	close(name);
}
setBatchMode(false);

end_time = getTime();
task_time = (end_time - start_time)/1000;

print("Fractal Dimension complete for all images segmented. Task complete.");
print("Time taken (s): " + task_time);

I think that the problem is that the macro is sequential, so the IJ Robot will run only after the Fractal Dimension command is finished, so what you want to do cannot be done with the IJ Robot.
I wonder if @mdoube would be able/willing to modify the dialog so it does not stop the process or have an alternative suggestion.

Thanks @gabriel. That makes sense. I thought this may have been a problem and tried reordering the commands, calling IJ Robot first but with an extended delay, and then calling Fractal Dimension. Alas this did not work; no doubt the same sequential problem.

There is a known bug in calling IJ2-style plugins from macro. Sometimes a hacky workaround works, but for Factal Dimension it doesn’t. I’ve removed these kinds of messages, so after the next update you won’t have to click OK, or wait(1000); any more.

2 Likes

Thankyou very much @mdoube. A quick question. I have had a look at Github and see that all the source code/java files etc are there but there does not appear to be a .jar file for the plugin. I take it that the next update you mention will generate the .jar file and enable BoneJ to be updated via the ImageJ update process?

Thanks again

Cameron

Yes, that’s right, just let the ImageJ updater run and install BoneJ updates when it prompts you.

You might also get some mileage out of the Particle Analyser, which can give you info about individual pores or sand grains.

Indeed, it’s a known bug, filed here in scijava-common:

… so I believe your newly opened issue is a duplicate:


To my knowledge, the general workaround is to annotate the message parameter with required = false explicitly.

Thankyou @mdoube.

I have run the ImageJ updater and installed the BoneJ updates (and re-run it after shutting ImageJ down to ensure that all plugins were up to date).

I have then re-run the macro and unfortunately the same dialog box appears (“NB: Translations affect runtime significantly”) .

Sorry to be a pain but the changes don’t appear to have the desired effect.

Regards

Cameron

@leckos please be patient, we haven’t made a new release yet. If you would like to follow it, please keep an eye on this branch, which is likely to be the next to get merged and released:

No worries @mdoube. I will do so. Thanks for your assistance and the information on Particle Analyser.

Regards

Cameron