简体   繁体   English

ImageJ Javascript脚本中的文件打开对话框

[英]File open dialog in ImageJ Javascript Script

I want to write a macro/script to open a file open dialog, and then import the selected image using BF with various options. 我想编写一个宏/脚本来打开文件打开对话框,然后使用带有各种选项的BF导入所选图像。

I found this JS script for doing the latter part here : 我发现此JS脚本可在此处完成后一部分:

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 regular macro language file open dialog here : 我还发现了常规的宏语言文件打开对话框, 在这里

File.openDialog(title)

How do I do both of these things in a JS script? 我该如何在JS脚本中同时做这两件事? Specifically, how do I create the file open dialog in JS? 具体来说,如何在JS中创建文件打开对话框?

If it is easier to do both in the macro IJM language, rather than Javascript, then how do I create a BF object and set the import options? 如果使用宏IJM语言(而不是Javascript)更容易执行这两种操作,那么如何创建BF对象并设置导入选项?

All the ImageJ macro functions are implemented in ij.macro.Functions , so you can find what you need in Functions.java 所有ImageJ宏函数都在ij.macro.Functions中实现,因此您可以在Functions.java找到所需的内容

  • From Javascript , you can use ij.io.OpenDialog : Javascript中 ,您可以使用ij.io.OpenDialog

     importClass(Packages.ij.io.OpenDialog); od = OpenDialog("Choose a file", null); folder = od.getDirectory(); file = od.getFileName(); path = folder + file; 
  • Alternatively, you can use the option string of the Bio-Formats Importer macro command, it's all in the macro you linked to : 另外,您可以使用Bio-Formats Importer 命令的选项字符串,所有这些都在您链接到宏中

     run("Bio-Formats Importer", "open=" + path + "autoscale color_mode=Default view=Hyperstack stack_order=XYCZT"); 

    To get the required options, simply use the macro recorder . 要获得所需的选项,只需使用宏记录器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM