Search code examples
imagejimagej-macro

Calculating surface and storing as Excel file


I'm new to imageJ and I am trying to analyze several images: I have a code that can analyze color threshold for a set of images in a directory and store them separately:

input = "/m_3/ImageJ/test_folder/";
output = "/m_3/ImageJ/finished2/";

function action(input, output, filename) {
    open(input + filename);
run("Set Scale...", "distance=872 known=9 pixel=1 unit=cm");
run("Color Threshold...");
// Color Thresholder 1.48v
// Autogenerated macro, single images only!
.
.
.
// Colour Thresholding-------------

saveAs("Jpeg", output + filename);
        close();
    }

setBatchMode(true); 
list = getFileList(input);
for (i = 0; i < list.length; i++)
        action(input, output, list[i]);
setBatchMode(false);

Now I want to calculate the area of the newly saved images and this should work with the function measure..

run("Measure");

How can I store the calculations in .xls or .csv -files? Is it also possible to calculate the area of all the files in one directory and store the results in just one .xls or .csv -file?


Solution

  • Have a look at the explanation how to apply a common operation to a complete directory on the Fiji wiki. You can open each of the newly save images, set a threshold, measure, and close each image as follows:

    open("/path/to/your/image.jpg");
    setAutoThreshold("Default");
    run("Measure");
    close();
    

    and paste that code into the Process Folder template (Templates > IJ1 Macro > Process Folder) of the script editor.

    The results table can afterwards be saved as an .xls file via File > Save As... or:

    saveAs("Results", "/path/to/your/file.xls");