【问题标题】:How to batch process ImageJ macro within a specific folder within multiple directories如何在多个目录中的特定文件夹中批处理 ImageJ 宏
【发布时间】:2019-12-19 03:06:40
【问题描述】:

我有一个嵌套文件结构,其中父文件夹包含多个不同类型数据的文件夹。我正在使用 ImageJ 宏脚本来批处理其中一个文件夹中的所有图像文件。我目前需要分别处理每个文件夹,但我想对文件夹进行批处理。我查看了多个文件夹的一些批处理,但似乎代码正在处理所有文件夹中的所有文件夹和文件。我只需要处理每个目录中的一个文件夹(都命名相同)。图像来自仪器,没有任何元数据,因此文件按原样保存以分隔实验,其中实验的所有数据都包含在父文件夹中。另外,我需要一个接一个地运行两个不同的脚本。如果我可以合并它们会很棒,但我也不知道该怎么做。

结构的一个例子是:

  • 实验 1/变量 1/已处理
  • 实验 1/变量 2/已处理

我目前正在每个“已处理”文件夹上单独运行我的宏。我想批处理每个“变量”文件夹中的每个“已处理”文件夹。

任何帮助将不胜感激,我对编码真的很陌生,我只是在努力尽可能地学习和自动化。

谢谢!

【问题讨论】:

    标签: imagej imagej-macro fiji


    【解决方案1】:

    您是否尝试过遇到的批处理脚本?阅读 ImageJ 提供的批处理示例让我相信它适用于您的示例。如果你还没有测试过,你应该这样做(你可以在你的实际宏的位置输入一个类似“print(list [i])”的命令,同时测试你的文件查找部分是否正常工作。

    要合并两个不同的脚本,最简单的选择是使它们成为单独的函数。即:

    // function to scan folders/subfolders/files to find files with correct suffix
    function processFolder(input) {
        list = getFileList(input);
        list = Array.sort(list);
        for (i = 0; i < list.length; i++) {
            if(File.isDirectory(input + File.separator + list[i]))
                processFolder(input + File.separator + list[i]);
            if(endsWith(list[i], suffix))
                processFile(input, output, list[i]);
                processOtherWay(input, output, list[i]);
        }
    }
    
    function processFile(input, output, file) {
        // Do the processing here by adding your own code.
        // Leave the print statements until things work, then remove them.
        print("Processing: " + input + File.separator + file);
        print("Saving to: " + output);
    }
    
    function processOtherWay(input, output, file) {
        // Do the processing here by adding your own code.
        // Leave the print statements until things work, then remove them.
        print("Processing: " + input + File.separator + file);
        print("Saving to: " + output);
    }
    

    如果目标不是在完全相同的图像上运行它们,那么再次使它们成为独立的函数,并将脚本的文件夹排序部分分为两部分,一个用于功能 1,另一个用于功能 2。

    【讨论】:

      【解决方案2】:

      您始终可以只使用您拥有的代码并将其嵌套在另一个或两个 for 循环中。

      numVariables = ;//number of folders of interest
      
      for(i = 1; i <= numVariables; i++) //here i starts at 1 because you indicated that is the first folder of interest, but this could be any number
      {
          openPath = "Experiment1/variable" + i + "/processed";
          files = getFileList(openPath);
          for(count = 0; count < files.length; count++) //here count should start at 0 in order to index through the folder properly (otherwise it won't start at the first file in the folder)
          {
              //all your other code, etc.
          }
      }
      

      我认为应该差不多了。

      【讨论】:

      • 我不知道我在做什么。我尝试了你的建议,但我无法让它发挥作用。我不知道“所有其他代码”中的内容,因此它将遍历列表并打开图像,执行这些操作,然后保存它。它只是一遍又一遍地打开相同的图像。你知道我哪里出错了吗?
      • 我很乐意提供帮助。您介意提供您当前正在使用的代码,以便我更好地了解您现在正在使用什么吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-10
      • 1970-01-01
      • 1970-01-01
      • 2021-12-07
      • 1970-01-01
      • 1970-01-01
      • 2017-11-14
      相关资源
      最近更新 更多