Search code examples
imagejimagej-macro

ImageJ batch processing: saving results of each image separately in the csv format


I have around 30 images and use ImageJ macros to analyse the particles (area, circularity, etc.) in the batch. From the macros script that I'm using, I'm not able to save the results separately, I mean one results.csv file per image. Script:

fileName = getTitle(); 

run("Set Scale...", "distance=231 known=200 unit=um");
//setTool("rectangle");
run("Select All");
makeRectangle(0, 0, 2560, 1856);
run("Crop");
run("8-bit");
setAutoThreshold("Default");
run("Threshold...");
setThreshold(0, 116);
setOption("BlackBackground", false);
run("Convert to Mask");
//run("Close");
run("Analyze Particles...", "size=80-Infinity display exclude summarize add");
selectWindow("Results");  //activate results table
saveAs("Results", "C:/folder/Results.csv");

Solution

  • In the final line, your script will save a file called Results.csv and then overwrite it when you save the next image. So you need to construct a unique path for the Results for each image.

    fileName = getTitle(); 
    
    run("Set Scale...", "distance=231 known=200 unit=um");
    //setTool("rectangle");
    run("Select All");
    makeRectangle(0, 0, 2560, 1856);
    run("Crop");
    run("8-bit");
    setAutoThreshold("Default");
    run("Threshold...");
    setThreshold(0, 116);
    setOption("BlackBackground", false);
    run("Convert to Mask");
    //run("Close");
    run("Analyze Particles...", "size=80-Infinity display exclude summarize add");
    selectWindow("Results");  //activate results table
    // construct unique path here using fileName
    path = "C:/folder/" + fileName + ".csv";
    saveAs("Results", path);