How to save the results in separate files after batch analysis

macro
Tags: #<Tag:0x00007fb879f91300>

#1

Hi,

I am a newcomer to batch analysis.
I will have to analyze about 200 images and in testing I have found the correct parameter. I am doing particle analysis and my problem is saving the summary results in different txt or csv files with the name of each file. Alternatively a single CSV file with each summary in a different row would also do.
Below is what I wrote.

Any hint of what I am doing wrong in line 4?

run("8-bit");
run("Auto Threshold", "method=Huang white");
run("Analyze Particles...", "size=50-6000 summarize");
saveAs("Results", "C:/Francisco Lopez/Image J analysis test/+"Summary"+fileName".csv");

Thanks a lot,
Francisco


#2

Hi @francislop,

if you want to save the summary table you first need to select it so that IJ recognizes it as active window. Then you can save it as a results table. This in turn will change the name of the results window. So if you want to collect results from different images in the same summary table you then will need to rename it back to the name “Summary” to do so. in my experience using .tsv as extension for results tables makes the table directly readable in excel.

This macro code shows how you can do this:

fileName = getTitle(); //needed to read in the name of the current image

run("Analyze Particles...", "summarize");
selectWindow("Summary");  //activate summary table
saveAs("Results", "C:/users/broch/Desktop/Summary" + fileName + ".tsv");  //save as tsv to make readability in excel easier
IJ.renameResults("Summary" + fileName + ".tsv", "Summary");  //rename back to summary

Hope this helps


#3

Hi,

thanks for your reply.
I can get some results, but in a very strange way.
I have been testing with 4 different images and when the batch is run, 4 files are generated, but the results of 2 of them are combined in 1 file, 1 file is empty, 1 shows the results OK, and the last shows all the particles that is something not needed.


#4

Hi @francislop,

sorry my mistake. That is because every image has a different name and the summary table is saved by using the file name. Thus we need to save that better under a fixed name as follows:

fileName = getTitle(); //needed to read in the name of the current image

run("Analyze Particles...", "summarize");
selectWindow("Summary");  //activate summary table
saveAs("Results", "C:/your/folder/of/choice/Summary.tsv");  //save as tsv to make readability in excel easier
IJ.renameResults("Summary.tsv", "Summary");

Hope this helps


#5

Hi,
I have a similar inquiry and id like to clarify if this solution will work. Please correct me if im wrong but in my understanding, the above macro will save the individual results file of images that are batch processed? I will need to save not just the summary but more importantly the results for individual images that contain information on different particles scattered in the images. I have a hundreds of images to process and will be needing an efficient way to look at the results.
Thank you in advance for your help.


#6

Hi @Yzabelle,

the macro works similarly with the results table. You need to make sure that the correct table window is selected. Thus, in your case it will be selectWindow("Results");instead of “Summary”.
The results table should normally not need a renaming but if it will become necessary you do it as for the summary table.

So you could adjust the macro accordingly:

fileName = getTitle(); //needed to read in the name of the current image

run("Analyze Particles...", "display summarize");
selectWindow("Results");  //activate results table
saveAs("Results", "C:/your/folder/of/choice/Results.tsv");
selectWindow("Summary");  //activate summary table
saveAs("Results", "C:/your/folder/of/choice/Summary.tsv");
IJ.renameResults("Summary.tsv", "Summary");

This macro will only process a single image but if you run it with ►Process ►Batch ►Macro… then you could apply it on a complete folder of images.


#7

Thank you for this @biovoxxel!
such a big help.