Posted by
ctrueden on
May 18, 2011; 7:44pm
URL: http://imagej.273.s1.nabble.com/Using-Bio-Formats-Importer-and-Javascript-tp3684545p3684546.html
Hi Jan,
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.
>
The Bio-Formats Importer now has a high-level Java API (and hence Javascript
API) for invoking it.
Try this:
String id = "/path/to/myFile.ext";
ImagePlus[] imps = BF.openImagePlus(id);
This imports the file with the last-used importer options. If you need more
control over the options, you can instead write:
String id = "/path/to/myFile.ext";
ImporterOptions options = new ImporterOptions();
options.setId(id);
options.setAutoscale(true);
options.setCrop(true);
options.setCropRegion(0, new Region(x, y, w. h));
options.setColorMode(ImporterOptions.COLOR_MODE_COMPOSITE);
//...etc.
ImagePlus[] imps = BF.openImagePlus(options);
This code should be adaptable to Javascript with minimal modifications.
As for thread safety, we have not heavily tested it in a multi-threaded
context, but I don't know of any obvious roadblocks to it working. Let us
know how it goes!
Regards,
Curtis
On Mon, May 16, 2011 at 9:59 AM, Jan Eglinger
<
[hidden email]>wrote:
> 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");
> }
>