我正在尝试创建一个脚本,它将遍历目录并打开图像并对其进行分析等。
所以我想将类似下面脚本的东西转换为循环;
//sets the pixel height and width
height = 15;
width = 15;
//navigates to the folder and opens the image
IJ.run("Raw...", "open=[C:\\Users\\Documents\\Ru\\simulations_Ru\\Batch1_sc\\1 Atoms\\15x15_stem_image00001_total_df_00001.bin] image=[64-bit Real] width=15 height=15 offset=0 number=1 gap=0");
imp = IJ.getImage();
//selects a region of interest I want to make measurements from
imp.setRoi(0, 0, width, height);
//makes the measurement
IJ.run(imp, "Measure", "");
//closes the image
imp.close();
我想知道的是如何将其转换为循环(而不必为每个文件夹键入命令),以便迭代特定文件夹的数量
答案 0 :(得分:1)
我如何阅读它,问题更多的是找到如何迭代目录中的文件。几个月前我一直在寻找这个问题,发现很难找到正确的信息,因为关于JavaScript的大部分内容都涉及在浏览器中运行,而无法访问&#34 ;本地"文件系统......
无论如何,在ImageJ中,可以使用以下JavaScript代码:
importClass(Packages.java.io.File);
var foo = File('/tmp/');
dirlist = foo.list();
for (var i = 0; i < dirlist.length; i++) {
print(dirlist[i]);
}
所以在&#34; for&#34;循环你可以打开文件,处理步骤并将结果写入新文件。
答案 1 :(得分:0)
height = 15;
width = 15;
var cmds = //cmds is a shortage of commands
[
"open=[C:\\Users\\Documents\\Ru\\simulations_Ru\\Batch1_sc\\1 Atoms\\15x15_stem_image00001_total_df_00001.bin] image=[64-bit Real] width=15 height=15 offset=0 number=1 gap=0",
"another command",
"and so on..."
];
for(var i in cmds)
{
IJ.run("Raw...", cmds[i]);
imp = IJ.getImage();
imp.setRoi(0, 0, width, height);
IJ.run(imp, "Measure", "");
imp.close();
}