设置imagej宏到批处理过程实验室图像

发布于 2025-02-13 04:41:23 字数 1379 浏览 1 评论 0原文

我目前正在尝试使用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"); 

任何帮助都将不胜感激。谢谢。

I'm currently trying to batch process a lot of lab images at once using ImageJ/Fiji but I'm having a hard time making it process the images. Whenever a file is pulled up, there are three images which are split into channels and open in separate windows . During the processing, each window is selected and needs to be processed differently. I am currently trying to figure out how to make the program select each different window based on a specific parameter rather than the exact name of the window. Each of the windows will end in "C=0", "C=1", or "C=2". I want the code to select the windows that contain the string "C=0", "C=1", or "C=2" in them but I can't seem to get it to work. As of now, it only runs through the first file but not the rest. The current code I'm running looks like this.

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"); 

Any and all help would be super appreciated. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天生の放荡 2025-02-20 04:41:23

如果要处理多个文件而不手动打开每个文件,则将所有文件放在同一文件夹中,然后编写一个for loop是很方便的。

这是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);
}

If you want to process several files without manually opening each, it's convenient to put all files in the same folder, and then write a for loop.

Here's an example in the ImageJ macro language, based on the code you provided:

// 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);
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文