Login  Register

Using Bio-Formats Importer and Javascript

Posted by Jan Eglinger-3 on May 16, 2011; 2:59pm
URL: http://imagej.273.s1.nabble.com/Using-Bio-Formats-Importer-and-Javascript-tp3684545.html

Dear all,

what is the easiest way to use the Bio-Formats Importer in a thread-safe
way within Javascript? I would like to have something like the following
macro, but save the ImagePlus in a variable imp for further processing.
So I'm looking for the equivalent of imp = IJ.openImage() for Bio-Formats.

See the code examples for details.

Thanks for your help,
Jan


// ImageJ macro code

dir1 = getDirectory("Choose Source Directory ");
dir2 = getDirectory("Choose Destination Directory ");
list = getFileList(dir);

for (i=0; i<list.length; i++) {
  if (endsWith(list[i], ".zvi")) {
    run("Bio-Formats Importer", "open=" + dir1 + list[i] + "autoscale
color_mode=Default view=Hyperstack stack_order=XYCZT");
    // process the image
    saveAs("TIFF", dir2+list[i]);
    close();
  }
}


I would have Javascript like:

// Javascript code
var dir1 = IJ.getDirectory("Choose Source Directory ");
var dir2 = IJ.getDirectory("Choose Destination Directory ");
var list = array(); // how do I get the file list of a directory in JS?

for (var i=0; i<list.length; i++) {
  // var imp = IJ.openImage(dir1 + list[i]);
  // here, instead of openImage, use Bio-Formats
  IJ.run("Bio-Formats Importer", "open=" + dir1 + list[i] + "autoscale
color_mode=Default view=Hyperstack stack_order=XYCZT");
  var imp = WindowManager.getCurrentImage();
  // process the image by using IJ.run(imp, "command");
  IJ.save(imp, dir2 + list[i] + ".tif");
}