【问题标题】:ImageJ Macro for converting multichannel Tiffs to Tiffs with only specified channels用于将多通道 Tiff 转换为仅具有指定通道的 Tiff 的 ImageJ 宏
【发布时间】:2015-06-22 14:55:15
【问题描述】:

我有一个非常简单的编程问题,希望有人能帮助我。

我正在处理具有多个通道的 Tiff 文件(全部包含在 Leica 格式的 .lif 文件中)。我想要一种方法可以轻松地将我的所有 Tiff 转换为仅包含几个通道(我指定)的 Tiff。现在我正在手动完成每个图像,这很乏味。我没有编写宏的经验,非常感谢一些帮助或起点。我确定这不是一个复杂的宏。

在我打开所有 Tiff 之后,我现在正在使用以下手动例程和命令:

  1. Image > Stacks > Stack to Images - 将堆叠的图像分离成单独的图像
  2. 关闭我不想在堆栈中的图像。
  3. Image > Stacks > Images to Stack - 将剩余的图像返回到堆栈并重命名。
  4. Image > Hyperstacks > Stack to Hyperstack - 我在这里改变它,使图像有 3 个通道。
  5. 使用所需的频道和名称保存新的 Tiff。
  6. 关闭 Tiff 并对所有 Tiff 重复。

我想要的是一个宏,它为所有打开的 Tiff 循环上述步骤,让用户指定频道(例如,保留频道:2,3 和 5)。我知道这是一个非常简单的编程任务,但我真的可以使用一些帮助来完成它。

谢谢! 约翰内斯

【问题讨论】:

    标签: tiff imagej imagej-macro


    【解决方案1】:

    有几种不太复杂的可能性来创建仅包含通道子集的堆栈:

    • Image > Stacks > Tools > Make Substack...,让您可以指定通道/切片,gets recorded 为:

      run("Make Substack...", "channels=1,3-5");
      
    • Image > Duplicate...,在这里可以选择连续范围的通道,比如:

      run("Duplicate...", "duplicate channels=1-5");
      

    要将此过程应用于文件夹中的所有图像,请查看 Script Editor 中的 处理文件夹 模板(模板 > IJ1 宏 > Process Folder ) 以及斐济 wiki 上的文档:

    【讨论】:

    • 谢谢!正是我需要让我开始。当我希望有时间实现它并获得一个工作宏时,我会发布一个更新。
    【解决方案2】:

    感谢 Jan Eglinger 的帮助,假期回来我设法编写了宏,在你的帮助下这很简单 :) 基于模板,它看起来像这样(我只是给了它们增量名称,这对我的目的来说很好,但我想可以做得更全面):

    /*
     * Macro to for converting multichannel Tiffs to Tiffs with only specified channels, processes multiple images in a folder
     */
    
    input = getDirectory("Input directory");
    output = getDirectory("Output directory");
    
    Dialog.create("File type");
    Dialog.addString("File suffix: ", ".tif", 5);
    Dialog.show();
    suffix = Dialog.getString();
    
    processFolder(input);
    
    function processFolder(input) {
        list = getFileList(input);
        for (i = 0; i < list.length; i++) {
            if(File.isDirectory(input + list[i]))
                processFolder("" + input + list[i]);
            if(endsWith(list[i], suffix))
                processFile(input, output, list[i]);
        }
    }
    
    function processFile(input, output, file) {
        open(input + file);
        print("Processing: " + input + file);
        run("Make Substack...", "channels=1,2,4"); //Specify which channels should be in the final tif
        print("Saving to: " + output);
        saveAs("Tiff", output + i);
        close("*");
    }
    

    【讨论】:

      猜你喜欢
      • 2022-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-22
      • 1970-01-01
      • 2017-03-30
      • 2020-05-16
      • 2010-11-01
      相关资源
      最近更新 更多