Macro: how to select the last row of the result table and copy it?

Hello everyone,

I’m trying to create a macro to count the number of nuclei in my images to use as normalization for my experiment.
I got to the point where I have a result table in which the number of rows is the number of nuclei, using the analyze particles function.
Now, I would like to select the last row (whose number is the number of nuclei) and to copy this number in a new table, attaching it to the name of my original image. Is it possible to do this on ImageJ ? If so, how ? I’m a beginner with macro development.

Thank you very much !

Here is an example macro that does what you describe. Also, read the Table functions at
to get an idea of what you can do with tables.

run("Blobs (25K)");
setOption("BlackBackground", false);
run("Convert to Mask");
run("Set Measurements...", "area mean display redirect=None decimal=3");
run("Analyze Particles...", "display clear");

image = getTitle();
nuclei = Table.size;

size = Table.size
Table.set("Label",size, image);
Table.set("Count",size, nuclei);

Thank you very much, it’s working ! I will save so much time

1 Like

Further to Jerome’s response, it might also be useful to know that you can use nResults to get the number of lines in a results table. E.g. print(nResults) prints the number of results to the log window.
If you need access to the data in a specific row and column of the results table, you can use the macro command getResult(“Column”, Row).
Hope this helps,


Thank you I will keep that in mind !