ImageJ: Batch Processing - Save results of single images in individual .csv files

Hello everyone,

I am new to this community and thus not very familiar with the structure and organization of the forum. If a question like mine was already adressed before, I apologize in advance.

So, let’s get to my question:

I am doing research on liquid foams and analyzed various bubbly liquids (with different compositions, conditions, etc…) under a numerical microscope. Here, i am interested in how the number of bubbles and the bubble sizes change over time. For every individual test, I aquired plenty of images (video with 15 fps for 10 min) and on each frame there are hundreds of bubbles to be analyzed. Self evidently, it takes ages to do that by hand. So, i need some automation to proceed more efficiently. I got familiar with the macro-recorder available in ImageJ and my macro (see below) works perfectly fine for one single image. But opening 600 images one after another, executing my macro, and saving the results is not the way i desire to spend my time. Thus, i was hoping to automatize the procedure using the batch-processing feature of ImageJ.

Macro
run(“8-bit”);
setAutoThreshold(“Default dark”);
//run(“Threshold…”);
//setThreshold(163, 255);
setOption(“BlackBackground”, false);
run(“Convert to Mask”);
//setTool(“rectangle”);
makeRectangle(144, 72, 1306, 1066);
run(“Analyze Particles…”, “size=15-Infinity circularity=0.80-1.00 show=[Overlay Masks] display exclude in_situ”);
saveAs(“Results”, “C:/Users/Camera1/Desktop/Results.csv”);

When I execute this macro in the batch-processing window, i face the following problems:

a) The results of the particle analysis of all images in the input directory are collected in one common “results” table.

b) I get only one csv file with all the aquired data from the particle analysis of all images in the input directory (basically the list mentioned in a) as csv file).

This makes it impossible for me to track changes of bubble sizes and bubble numbers over time as i can’t relate the data to the image it was aquired from. What would definitely help me to solve this problem, is a macro that displays the results of the particle analysis of every individual image in the input directory in a separate results list and saves these separate result lists as separate csv files.

Unfortunately, i don’t have much programming experience (and basically no experience with java whatsoever). I would thus highly appreciate every bit of help that you can offer to me. Thanks in advance!

Best regards,
Martin

First off, it is best to format scripts as code using the </> button.

As far as the question, I would say you need two additional steps. Your output is always in the same place, so you need to add some sort of variable to the file name you are outputting. Otherwise you overwrite. The forum will not know what you want the names to be without more information (part of the file name, a number at the end of each, plenty of other options).
You can get the image “name” using something like
name = getTitle()
https://imagej.nih.gov/ij/developer/macro/functions.html

Second, you probably want a run("Clear Results"); at the end so the results table does not fill up as you go through the images. As shown here in a more complicated script: How to measure the area of the cells within each detected colonies
That does something similar where they are outputting many CSV files.

That script also has examples of adding variables into the file name if you search for it’s saveAs function.