【问题标题】:Setting up ImageJ Macros to batch process lab images设置 ImageJ 宏以批处理实验室图像
【发布时间】:2022-08-09 01:05:52
【问题描述】:

我目前正在尝试使用 ImageJ/Fiji 一次批量处理大量实验室图像,但我很难让它处理图像。每当拉起文件时,就会有三个图像被分成通道并在单独的窗口中打开。在处理过程中,每个窗口都被选中,需要进行不同的处理。我目前正在尝试弄清楚如何使程序根据特定参数而不是窗口的确切名称来选择每个不同的窗口。每个窗口都将以 \"C=0\"、\"C=1\" 或 \"C=2\" 结尾。我希望代码选择其中包含字符串 \"C=0\"、\"C=1\" 或 \"C=2\" 的窗口,但我似乎无法让它工作.到目前为止,它只运行第一个文件,而不运行其余文件。我正在运行的当前代码如下所示。

open(\"/Users/name/Desktop/name of file\");
selectWindow(\"name of window - C=1\");
setOption(\"ScaleConversions\", true);
run(\"8-bit\");
setAutoThreshold(\"Default\");
//run(\"Threshold...\");
//setThreshold(0, 10);
setOption(\"BlackBackground\", true);
run(\"Convert to Mask\");
run(\"Convert to Mask\");
run(\"Analyze Particles...\");
close();
run(\"Close\");
selectWindow(\"name of window - C=0\");
setOption(\"ScaleConversions\", true);
run(\"8-bit\");
setAutoThreshold(\"Default\");
//run(\"Threshold...\");
//setThreshold(0, 20);
run(\"Convert to Mask\");
run(\"Convert to Mask\");
run(\"Analyze Particles...\", \"size=20-700 show=Overlay display summarize add composite\");
run(\"Analyze Particles...\");
roiManager(\"Show None\");
roiManager(\"Show All\");
run(\"Close\");
close();
run(\"Close\");
selectWindow(\"name of window - C=2\");
setOption(\"ScaleConversions\", true);
run(\"8-bit\");
setAutoThreshold(\"Default\");
//run(\"Threshold...\");
//setThreshold(0, 4);
run(\"Convert to Mask\");
run(\"Convert to Mask\");
run(\"Analyze Particles...\");
saveAs(\"Results\", \"/Users/name/Desktop/results/Summary.csv\"); 

任何和所有的帮助都将非常感激。谢谢你。

  • 我不完全了解您需要什么帮助。所以代码工作正常你只想在多个文件上运行它?

标签: imagej fiji imagej-macro


【解决方案1】:

如果要处理多个文件而不需要手动打开每个文件,可以方便地将所有文件放在同一个文件夹中,然后编写一个 for 循环。

这是 ImageJ 宏语言中的一个示例,基于您提供的代码:

// Edit these variables to have your folder paths
inputfolder = "MY_INPUT_FOLDER";
imagefolder = "MY_IMAGE_FOLDER";
outputfolder = "MY_OUTPUT_FOLDER";

// Find out how many files are in the folder
list = getFileList(inputfolder + imagefolder);
num2process = list.length;

// Loop through all files in the folder
for (l = 0; l < num2process; l++) 
{
    open(inputfolder + imagefolder + list[l]);
    
    // After opening, the image is in focus, so get its properties
    filename = getInfo("image.filename");
    current_title = getTitle(); 
    current_image = getImageID();
    selectImage(current_image);   // this puts the image in focus
    
    // With the image selected, process it
    run("Split Channels");
    
    // The channels will have the following names:
    channel1 = "C1-" + current_title; 
    channel2 = "C2-" + current_title; 
    channel3 = "C3-" + current_title;

    // Put them in an array for convenience
    array = newArray(channel1, channel2, channel3); 
    
    // If the processing steps are the same, it's convenient to loop through each channel
    for (channel = 0; channel <=2; channel++) 
    {
        // Select the right channel
        image = array[channel];
        selectWindow(image);
        
        // Apply image processing
        setOption("ScaleConversions", true);
        run("8-bit");
        setAutoThreshold("Default");
        run("Convert to Mask");
        run("Analyze Particles...", "size=20-700 show=Overlay display summarize add composite");    
        run("Close");
    }
    
    // Save the results and name the file appropriately
    string = outputfolder + filename + "_summary.csv";
    saveAs("Results", string);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多