Login  Register

Multiple results output from batch mode command line

Posted by jeremydouglass on Feb 23, 2009; 7:38pm
URL: http://imagej.273.s1.nabble.com/Multiple-results-output-from-batch-mode-command-line-tp3693589.html

I'm trying to adapt a series of scripts for use with the -batch command line option for GUI-less operation. I'm struggling however to understand the basics of how execution differs.

Example: I'm currently trying to run the "measure" command on a directory of images in command line batch mode and generate a single output file.

I've written a macro file "measuretest.txt"

macro "measuretest" {
    dir = getDirectory("Choose a Directory ");
    list = getFileList(dir);
    setBatchMode(true);
    for (i=0; i<list.length; i++) {
        path = dir+list[i];
        showProgress(i, list.length);
        if (!endsWith(path,"/")) open(path);
        if (nImages>=1) {
            run("Measure");
            close();
        }
    }
    saveAs("Measurements", "Results.xls");
}

When I run this from the ImageJ GUI (Fiji > Plugins > Macros > Run "measuretest.txt") or from the command line in macro mode ("java -jar ij.jar -macro measuretest.txt") and choose a directory of 10 images, the result is a "Results.xls" file containing the full results.

1 circle-01.png 50.82 46.00
2 circle-02.png 3.13 23.54
3 circle-03.png 150.46 32.76
...
10 circle-10.png 16384 206.34

However, when I run the same macro in batch mode ("java -jar ij.jar -batch measuretest.txt") the terminal output shows line 1 of the results table being written to over and over again, and the output "Results.xls" is a 1-result file containing the last output.

1 circle-10.png 16384 206.34

A further unexpected difference was that while -macro wrote the "Results.xls" file to the root directory, -batch writes the file to the working directory from which ij.jar was invoked.

How do I fix this example to generate a single output file in -batch mode?
Thanks for your time.

-- Jeremy

NOTE: There was a similar old thread (http://n2.nabble.com/batch-measurements-to-single-data-file-td635183.html#a635183) about accidentally clearing the results table with each measure, but the solution didn't seem to pertain.