Batch Processing Analyze Particles - Export of Summary and Results

Hello everybody,

I’m new to macro writing in ImageJ. I have a time lapse of pictures where new particles are generated and I would like to count the particles at each time point. For this I wrote a makro that automatically opens each picture from a folder, makes it binary and counts the particles. It saves all the results for each picture and works fine for the beginning. But at the moment I only get the results for each picture individually.

  1. Can I somehow combine the results summary table for each picture to one table?

  2. What is the most convenient way to export my summary to excel or origin?

  3. Are the numbers from the result table in pixels or in the unity of my scalebar?

Thanks a lot for your help! I put my code in here for a better understanding. Any other hints are welcome, too!

// Öffnet Fenster, bei dem Input Ordner ausgewählt werden muss
inputDir1 = getDirectory(“Choose Pictures-Originalbilder”);
// Öffnet Fenster, bei dem Output Ordner ausgewählt werden muss
outputDir = getDirectory(“Choose Output Location”);

// Zählt die Anzahl aller Bilder in dem Input Ordner
fileList1 = getFileList(inputDir1);

//Startet eine Schleife die sich für alle Bilder im Inputordner wiederholt
for (i = 0; i < fileList1.length; i++) {

//ordnet Variable Bild i zu
file1 = fileList1[i];
filex = inputDir1 + file1;

//Öffnet Bild i
run("Bio-Formats", "open=[filex] autoscale color_mode=Default open_files rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT");

// Bildoptimierung

//Brightness und Contrast optimieren
//setMinAndMax(63509, 65535);
//run("Apply LUT");
run("Enhance Contrast...", "saturated=0.05 normalize");

//Hintergrund korrigieren
run("Subtract Background...", "rolling=12 light");

//Zwischenergebnis mit Scalebar speichern und schließen

//Bild duplizieren
run("Duplicate...", " ");

//Scalebar in ein Bild einfügen
run("Scale Bar...", "width=50 height=40 font=60 color=White background=Black location=[Lower Right] bold overlay");

//Optimiertes Bild mit Scalebar wird neuer Name gegeben (rosa Teil kann umbenannt werden)
outName = File.getName(file1) + "_scalebar";
//Outputbild wird abgespeichert in Output Ordner
saveAs("PNG", outputDir + "/" + outName);

//Bild mit Scalebar wird geschlossen
filey = File.getName(file1) + "_scalebar";
close("filey");

//Originalbild wird markiert
selectWindow(file1);

//Bild binär machen

//Treshhold wird eingestellt
setThreshold(0, 58821);
run("Convert to Mask");

//Binär machen
run("Make Binary");

//Löcher innerhalb der Strukturen füllen
run("Fill Holes");

//Partikel die nahe beieinanderliegen trennen
run("Watershed");

//Bild duplizieren
run("Duplicate...", " ");

//Zwischenergebnis von binärem Bild speichern und schließen

//Binärem Bild wird neuer Name gegeben (rosa Teil kann umbenannt werden)
outName = File.getName(file1) + "_binär";
//Outputbild wird abgespeichert in Output Ordner
saveAs("PNG", outputDir + "/" + outName);

//Binäres Bild wird geschlossen
filez = File.getName(file1) + "_binär";
close("filez");

//Originalbild wird markiert
selectWindow(file1);

//Partikelanalyse

//Partikel zählen
run("Analyze Particles...", "size=8-Infinity pixel show=Outlines display exclude clear summarize");

//Zwischenergebnis der erkannten Partikel als PNG speichern und schließen

//Bild mit gezählten Partikeln wird neuer Name gegeben (rosa Teil kann umbenannt werden)
outName = File.getName(file1) + "_particles";
//Outputbild wird abgespeichert in Output Ordner
saveAs("PNG", outputDir + "/" + outName);

//Bild mit gezählten Partikeln wird geschlossen
filea = File.getName(file1) + "_particles";
close("filea");

//Summary als excel speichern und schließen

//Summary speichern
selectWindow("Summary");
saveAs("Results", outputDir + File.getName(file1) + "_Summary.xls"); 

//Summary schließen
close(File.getName(file1) + "_Summary.xls");

//Results als excel speichern und schließen

//Summary speichern
selectWindow("Results");
saveAs("Results", outputDir + File.getName(file1) + "_Results.xls"); 

//Summary schließen
close("Results");

//Schließen aller Fenster

//Schließt alle Fenster
close("*");

//Schleife beendet
}

Good day Ann-Kathrin,

just some remarks:

Never ever set a fix threshold for scientific work, because it poses problems with replication and generalization. Always use one of the automatic threshold schemes. If none works for you, you have to improve your image acquisition process or the image pre-procesing.

If you omit “clear” in the call

run("Analyze Particles...", ... );

consecutive mesurements are appended to both tables.

If you set a scale to your image, the results can be displayed in the corresponding units. Please study the ImageJ User Guide and see the “Analyze Particle”-dialog after a scale has been set to the image.

I would always export data as tab-delimited file.
ImageJ exports as comma delimited file which sometimes poses problems with Excel which I wouldn’t recommend anyway.

HTH

Herbie

1 Like

Hello Herbie,

thanks a lot for the fast and easy solutions! I omitted the “clear” in

run("Analyze Particles...", "size=1-Infinity show=Outlines display exclude  summarize");

and it works. I changed the savings of the results and now I have one result table for each picture, which is saved during the loop. But one summary table for all pictures which is saved after the loop. Perfect!

I also changed the units to my scalebar (omitting the pixel in “Analyze Particles” and working with a picture with scalebar). And the output via tab-delimited file works, too.

Now I absolutely have to take care about my threshold. Thanks for that hint! Could you recommend an automatic threshold?

Could you recommend an automatic threshold?

No, it must be chosen according to the properties of your images.

The automatic thresholds are computed from the histograms of your images by following a specific strategy. You have to choose a scheme that works with most of the images that you like to process. Then the strategy of this scheme assumes that the histogram-shape is common to all of your images. If this is not the case, you may be lucky with another scheme but generally you need to change the properties of your images which means, as noted before, optimized image acquisition or image pre-processing.

Because I don’t know your images and especially not the whole bunch of images you like to process, the decision about the scheme must be left entirely to you.

Please accept that you need to understand what you are doing and of course you need to understand what the various processing possibilities really mean.

Regards

Herbie