按特定顺序在文件上调用ImageJ宏



我是ImageJ的新手,所以我甚至不确定我应该寻找什么来找到这个问题的答案。

我有一堆图像文件在一个文件夹(TIF)。我已经编写了一个宏来将文件拆分为RGB通道,然后将它们保存到相同的目录中。因此输出如下所示:

-File 1-blue.tif
-File 1-green.tif
-File 1-red.tif
-File 2-blue.tif
-File 2-green.tif
...
etc.

接下来我使用JACoP插件,它需要两个图像文件并计算输入之间的各种相关系数/分析。对于每个目录,我想做以下操作:

设置全局设置:

  1. 在阈值页签中设置参数
  2. 选择待分析的"Pearson’s系数"one_answers"M1、M2系数"执行

然后对目录中的每个文件循环执行以下命令:

  • 将输入文件1设置为文件X(红色),文件2设置为文件X(蓝色)
  • 点击Analyze
  • 将输入文件1设置为文件X(红色),文件2设置为文件X(绿色)
  • 点击Analyze
  • 设置输入文件1为文件x(蓝色),文件2为文件x(绿色)
  • 点击Analyze
  • 最后:

  • 保存分析输出日志
  • 问题是我不知道如何告诉ImageJ如何按顺序调用每个颜色文件。我如何指定它以三个块为单位提取文件,分析它们,然后转到下一个三个块?

    我只需要一些关于通用算法和可能的函数的基本帮助,我可能需要让我开始-我可以自己编写实际的宏代码。

    EDIT:我刚刚想到,我可以通过使用r将文件传递给ImageJ宏,每组三个,像这样:

    file_list <- list.files(getwd())
    rgbFiles <- file_list[grep(pattern = "blue|green|red", file_list)]
    rgbFilesSplit <- split(rgbFiles, ceiling(seq_along(rgbFiles)/3))
    

    所以在设置完工作目录后,我只是把rgb文件提取出来,并把它们分成一个列表。

    如果这种方法是有效的,那么我如何在子列表中描述的每个文件上调用ImageJ宏?我已经知道如何调用宏并使用R system()函数指定输入目录,但是我如何让ImageJ接收输入文件,这些文件只是从上面的R代码生成的文件名字符串?

    我在ImageJ邮件列表上问了这个问题。用户Joost Willemse在形成最后的宏时帮了我很大的忙。下面是完整的宏:

    dir=getDirectory("Choose a Directory");
    list = getFileList(dir);
    Array.sort(list);
    for (i=0; i<list.length; i+=3) {
        open(list[i]);
        blue=getTitle;
        open(list[i+1]);  
        green=getTitle;
        open(list[i+2]);
        red=getTitle;
        run("JACoP ", "imga="+red+" imgb="+blue+" thra=648 thrb=517 pearson mm");
        run("JACoP ", "imga="+red+" imgb="+green+" thra=648 thrb=517 pearson mm");
        run("JACoP ", "imga="+blue+" imgb="+green+" thra=648 thrb=517 pearson mm");
        close(red);
        close(green);
        close(blue);
    }
    

    设置目录后,开始for循环。i+=3允许迭代器以三步为单位计数(当我问这个问题时,我不知道这是可能的)!现在打开这三张图片,并保存它们的标题。最后,通过连接将标题发送到run()函数的字符串部分。然后图像关闭。只要在目录中对列表进行了正确排序,就可以正常工作。确保在JACoP的run()函数中设置阈值!!

    此外,我在r中使用grep()gsub()从日志中剥离系数值,这不是最有效的方法,但它完成了工作。您可以根据需要对从日志文件中提取的内容修改此代码:

    # This function takes the path to the log file. It then removes the Pearson's Coefficent, Manders M1/M2, and thresholded Manders M1/M2. It then gathers them into a table. 
    extract <- function(data){
        dat <- read.table(data, header = FALSE, sep = "", fill = TRUE, stringsAsFactors = FALSE)
        dat <- dat[ , "V1"]
        coef <- dat[grep(pattern = "=", dat)]
        coef <- as.numeric(gsub("r=|M1=|M2=", "",coef))
        coef <- split(coef, ceiling(seq_along(coef)/5))
        coef <- do.call(rbind.data.frame, coef)
        names(coef) <- c("r", "M1", "M2", "M1(T)", "M2(T)")
        coef <- cbind(Value = c("Red/Blue", "Red/Green", "Blue/Green"), coef)
        return(coef)
    }
    

    注意,coef <- as.numeric(gsub("r=|M1=|M2=", "",coef))需要根据您从日志文件中提取的内容进行修改。coef <- split(coef, ceiling(seq_along(coef)/5))也是如此——将5更改为日志文件报告的事件数。

    # Now just split the table into a list for each of the different analysis combinations fed into JACoP. Here I assume you set the output of the extract function to "dat".
    output <- split(dat, dat$Value)
    

    输出是输入宏的每个图像的所有分析值的列表,这些分析值由所分析的不同JACoP颜色通道划分。例如:

    $`Red/Blue`                 
    Value       r           M1          M2          M1(T)       M2(T)
    Red/Blue    0.743871077 0.395698602 0.963246489 0.513951407 0.700130944
    Red/Blue    0.460021089 0.605613993 0.456788982 0.125648321 0.424468211
    Red/Blue    0.967115553 0.357528694 0.767577893 0.073250688 0.720399867
    $`Red/Green`                
    Value       r           M1          M2          M1(T)       M2(T)
    Red/Green   0.79367778  0.36556424  0.722980958 0.487698812 0.381559727
    Red/Green   0.262211518 0.063695185 0.653330753 0.276610328 0.132548249
    Red/Green   0.483240639 0.348516661 0.961846834 0.832706515 0.356203613
    $`Blue/Green`                   
    Value       r           M1          M2          M1(T)       M2(T)
    Blue/Green  0.549159913 0.834823152 0.389143503 0.655878106 0.446664812
    Blue/Green  0.144388419 0.844781823 0.534304211 0.79041495  0.844326066
    Blue/Green  0.805481028 0.344139017 0.490682901 0.246814106 0.641006611
    

    最新更新