使用宏位于文件夹和子文件夹中的图像中的宏自动化任务



我最近发现了宏以及它们如何使我在斐济/imagej上工作的生活令人惊讶。

我创建了这个宏:

run("Image Sequence...", "open=/home/mario/Desktop/prueba/1/Image-000002.tif");
selectWindow("1");
//setTool("rectangle");
makeRectangle(406, 346, 1132, 845);
run("Z Project...", "projection=[Average Intensity]");
saveAs("Tiff", "/home/mario/Desktop/prueba/1/AVG_1.tif");

此宏的作用是导入存储在引用文件夹中的图像序列,使用模板匹配插件对齐图像堆栈,以使用z项目功能(Image> stacks> Z Project ...(并使用TIFF扩展名将新生成的图像保存在同一文件夹中。

但是,我确实有一个通用文件夹,其中包含大量的子文件夹,上面填充了TIFF文件,因此在每个文件夹中使用以前的宏也可能会成为一项繁琐的任务。我遇到了处理批处理处理的宏:

// "BatchProcessFolders"
//
// This macro batch processes all the files in a folder and any
// subfolders in that folder. In this example, it runs the Subtract 
// Background command of TIFF files. For other kinds of processing,
// edit the processFile() function at the end of this macro.
   requires("1.33s"); 
   dir = getDirectory("Choose a Directory ");
   setBatchMode(true);
   count = 0;
   countFiles(dir);
   n = 0;
   processFiles(dir);
   //print(count+" files processed");
   function countFiles(dir) {
      list = getFileList(dir);
      for (i=0; i<list.length; i++) {
          if (endsWith(list[i], "/"))
              countFiles(""+dir+list[i]);
          else
              count++;
      }
  }
   function processFiles(dir) {
      list = getFileList(dir);
      for (i=0; i<list.length; i++) {
          if (endsWith(list[i], "/"))
              processFiles(""+dir+list[i]);
          else {
             showProgress(n++, count);
             path = dir+list[i];
             processFile(path);
          }
      }
  }
  function processFile(path) {
       if (endsWith(path, ".tif")) {
           open(path);
           run("Subtract Background...", "rolling=50 white");
           save(path);
           close();
      }
  }

但是,由于我不是编码专家,所以我不知道如何合并在宏中写的自动任务。

总结一下,我想从选择的根目录中自动运行每个文件夹和子文件夹中的宏。

任何人都可以编辑并合并以前的宏来完成我的要求吗?

以防万一有人遇到这个问题,可以在imagej论坛中找到答案。

最新更新