Opening image file with open() and auto-clicking on OK

Hello,
I’m new to the ImageJ language. I want to create a macro in ImageJ to extract the images from multiple hyperstack files. I mananged to get a list of hyperstack files (*.cxd) with the getFileList(), but when I run open() on each of them:

list = getFileList(dir)
for (i=0; i<list.length; i++)
{
  open(dir+list[i]);
}

I am prompted with a ‘Bio-Formats Import Options’ dialog box, where I only need to click OK. This is expected, but I was wondering if it is possible to ‘auto-click’ the OK button such that the macro does not require user interaction.

Thank you

Hi @tomas !

Welcome to ImageJ and the Forum!

So… Here are some super helpful links to get you started with Scripting in ImageJ:

There is a great script example:

/*
 * Macro template to process multiple images in a folder
 */

#@ File (label = "Input directory", style = "directory") input
#@ File (label = "Output directory", style = "directory") output
#@ String (label = "File suffix", value = ".tif") suffix

// See also Process_Folder.py for a version of this code
// in the Python scripting language.

processFolder(input);

// function to scan folders/subfolders/files to find files with correct suffix
function processFolder(input) {
	list = getFileList(input);
	list = Array.sort(list);
	for (i = 0; i < list.length; i++) {
		if(File.isDirectory(input + File.separator + list[i]))
			processFolder(input + File.separator + list[i]);
		if(endsWith(list[i], suffix))
			processFile(input, output, list[i]);
	}
}

function processFile(input, output, file) {
	// Do the processing here by adding your own code.
	// Leave the print statements until things work, then remove them.
	print("Processing: " + input + File.separator + file);
	print("Saving to: " + output);
}

This script utilizes Script Parameters for dealing with folders/files… they are so helpful to use!

There is also a great working example using that same code (opening files via Bio-Formats automatically) in the Scripting Workshop - on this slide.

Hope this helps!

eta :slight_smile:

Hello eta,
thank you very much for the examples and the links, they are very helpful and are exactly what I needed.

Best regards!

1 Like

Great @tomas - I’m glad that helped! And if you have more questions after all of this… post again. We are here to help!

eta

If anybody is facing the same problem, here’s how you solve it:
Instead of running open(dir + list[i]), run the following:

run("Raw...", "open='" + dir + list[i] + "'image='16-bit Unsigned' width=1920 height=1080 offset=0 number=1 gap=0 little-endian");

* Change your parameters accordingly (e.g. width / height)…