Page 1 of 1

File open dialog in JS script

PostPosted: Wed Dec 09, 2015 9:42 pm
by balter@ohsu.edu
I want to write a macro/script to open a file open dialog, and then import the selected image using BF with various options.

I found this JS script for doing the latter part here:

Code: Select all
importClass(Packages.loci.plugins.BF);
importClass(Packages['loci.plugins.in.ImporterOptions']); // 'in' is a reserved word, hence the different syntax
importClass(Packages.loci.common.Region);

var path = "/path/to/file";
var options = new ImporterOptions();
options.setId(path);
options.setAutoscale(true);
options.setCrop(true);
options.setCropRegion(0, new Region(x, y, w. h));
options.setColorMode(ImporterOptions.COLOR_MODE_COMPOSITE);
var imps = BF.openImagePlus(options);

imps[0].show();


I also found the file open dialog here:
Code: Select all
File.openDialog(title)


How do I do both of these things in a JS script? Specifically, how do I create the file open dialog in JS?

If it is easier to do both in a macro ijm script, then how do I access BF and set the import options?

Re: File open dialog in JS script

PostPosted: Mon Dec 14, 2015 3:54 pm
by bramalingam
Hi,

Thank you for your interest in Bio-Formats.

ImageJ/FIJI offers a "recorder" plugin, which records your mouse clicks during a manual workflow as a Macro/Javascript or Plugin.
The documentation for the same can be found here,
http://imagej.nih.gov/ij/docs/guide/146-31.html

Please repeat your manual workflow(import an image using the Bio-Formats Importer after starting the “recorder”, but instead of the default macro option, select the Javascript option in the drop-down menu in the "recorder" window). This will record the arguments and the api call at the same time and print it on the recorder window.

Please take a look at the following example of mine:
IJ.run("Bio-Formats Importer", "open=/Users/bramalingam/Desktop/test.jpg autoscale color_mode=Default display_metadata display_ome-xml display_rois split_focal split_timepoints split_channels view=Hyperstack stack_order=XYCZT");

The above example will open the importer dialog and also sets the options argument.
You could repeat the same workflow as above and record the appropriate calls in Java Script, using the "recorder" plugin.

Hope that helps.

Best,
Balaji