We're Hiring!

File open dialog in JS script

Historical discussions about the Bio-Formats library. Please look for and ask new questions at https://forum.image.sc/tags/bio-formats
Please note:
Historical discussions about the Bio-Formats library. Please look for and ask new questions at https://forum.image.sc/tags/bio-formats

If you are having trouble with image files, there is information about reporting bugs in the Bio-Formats documentation. Please send us the data and let us know what version of Bio-Formats you are using. For issues with your code, please provide a link to a public repository, ideally GitHub.

File open dialog in JS script

Postby balter@ohsu.edu » Wed Dec 09, 2015 9:42 pm

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?
balter@ohsu.edu
 
Posts: 1
Joined: Wed Dec 09, 2015 6:55 pm

Re: File open dialog in JS script

Postby bramalingam » Mon Dec 14, 2015 3:54 pm

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
User avatar
bramalingam
 
Posts: 70
Joined: Tue Jan 14, 2014 12:01 pm


Return to User Discussion [Legacy]

Who is online

Users browsing this forum: No registered users and 1 guest