【问题标题】:Operations in a for loop only apply to the last file in imageJfor 循环中的操作仅适用于 imageJ 中的最后一个文件
【发布时间】:2019-11-29 11:35:04
【问题描述】:

我有一个图像文件夹,我想从中减去背景文件。我将背景文件存储在另一个文件夹中。我在下面写了宏,但它只对最后一个文件起作用:

setBatchMode(true); 

input_to_files = "C:/Users/user/Desktop/FL_20191115_40540 PM/";
input_to_BG =  "C:/Users/user/Desktop/BG/";
output = "C:/Users/user/Desktop/SumZ/";

function action(input_file, filename, inputBG, bg, output) {
        open(input_file + filename);
        open(inputBG + bg);
        imageCalculator("Subtract create stack", filename, bg);
        saveAs("tif", output + filename);
        close();
}

list = getFileList(input_to_files);
background =  getFileList(input_to_BG);

for (i = 0; i < list.length; i++)
        filename = list[i];
        bg = background[0];
        action(input_to_files, filename, input_to_BG, bg, output)

setBatchMode(false);

【问题讨论】:

    标签: image-processing imagej


    【解决方案1】:

    你的 for 循环应该用大括号括起来,循环的最后一行需要一个终止分号:

    for (i = 0; i < list.length; i++) {
            filename = list[i];
            print(filename);
            bg = background[0];
            action(input_to_files, filename, input_to_BG, bg, output);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-27
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多