ImageJ中的批处理引发错误“没有打开的图像”

时间:2018-10-03 00:34:17

标签: macros batch-processing imagej

我正在尝试编写一个小的脚本,该脚本将对ImageJ中的一系列图像执行一些操作。我使用了https://imagej.net/Batch_Processing中描述的脚本模板方法,但是遇到一个错误消息,提示没有打开任何图像。对我来说,这的整个想法是拥有无需打开图像即可执行和处理图像的代码。我尝试使用同一网站上概述的“处理▶批处理▶宏...”方法,但似乎没有问题。但是这里的问题是,我希望能够简单地将我编写的脚本发送给我的队友,而不必向他们解释任何事情,从而使他们能够自己运行代码,而又无需打开图像有数百张图像时会出现问题。

这是我到目前为止的代码。现在应该做的就是在图像上创建一堆正方形,然后在图像的%area上进行测量,然后显示结果。

/*
 * Macro template to process multiple images in a folder
 */

requires("1.33s");
setBatchMode(true);
#@ File (label = "Input directory", style = "directory") input
#@ File (label = "Output directory", style = "directory") output
#@ String (label = "File suffix", value = ".tif") suffix


// See also Process_Folder.py for a version of this code
// in the Python scripting language.

processFolder(input);

// function to scan folders/subfolders/files to find files with correct suffix
function processFolder(input) {
    list = getFileList(input);
    list = Array.sort(list);
    for (i = 0; i < list.length; i++) {
        if(File.isDirectory(input + File.separator + list[i]))
            processFolder(input + File.separator + list[i]);
        if(endsWith(list[i], suffix))
            processFile(input, output, list[i]);
    }
}

function processFile(input, output, file) {
    // Do the processing here by adding your own code.
    // Leave the print statements until things work, then remove them.

    run("ROI Manager...");
    roiManager("Show All");
    setTool("rectangle");
    for (i = 1; i < getWidth/2; i++) {
        makeRectangle(getWidth/2 - i, getHeight/2 - i, 2*i + 1, 2*i + 1);
        roiManager("Add");
    }
    run("Set Measurements...", "area area_fraction redirect=None decimal=3");
    roiManager("multi-measure measure_all one append");
    run("Summarize");
}

现在我要弄清楚的是如何解决未打开图像的错误,代码本身的功能只是一个粗略的草图。我试过使用setBatchMode(“ true”),但这似乎没有用。如果有人有任何想法或建议,我将不胜感激!

0 个答案:

没有答案