2

I'm brand new to imageJ and its macros, I can't save a Results file from Particle Analyze in a loop.

Here is my code, made of what I just learned on internet and I just can't include [i] in the saveAs function and there is a mismatch with the saving of the images while I have not even try yet to save it...

path1=getDirectory("Mydir");
list=getFileList(path1);
path2=getDirectory("My output dir");
setBatchMode(true);

for(i=0;i<list.length;i++){
    open(path1+list[i]);
    run("8-bit");
    run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00 show=[Bare Outlines] display clear");
    selectWindow("Results");
    saveAs("Results", path2+"Results.xls");
    close();
} 
setBatchMode(false);
run("Close");
Jan Eglinger
  • 3,995
  • 1
  • 25
  • 51
Sarahdata
  • 309
  • 3
  • 15

1 Answers1

1

To save the Results window in each cycle of your for loop, you can add the counter variable i to the file name string:

saveAs("Results", path2+"Results" + i + ".xls");

It might be a good idea to also include the original image file name into the results file name, such as:

saveAs("Results", path2+"Results" + list[i] + ".xls");

NB: I had to add to add setAutoThreshold("Default"); before the Analyze Particles... command to make your macro work on sample images like the Blobs example image, because the command need a thresholded/binary image.

Jan Eglinger
  • 3,995
  • 1
  • 25
  • 51
  • Thanks Jan. It saves my first "results" file but then I get a warning message : "it appears that the directory (the one for saving, path2!) does not have TIF, JPEG, BMP, (...) files." How come it goes read in that folder ? NB : I indeed work with binary images. – Sarahdata Sep 02 '15 at 06:27
  • It is because my "save" directory was in my "process" directory. I works fine ! – Sarahdata Sep 02 '15 at 06:35