A flexible macro/plug-in for counting different objects in the same photo?

Hi all, I’m a complete imagej newbie so apologies in advance if I’m missing something obvious.

I’ve been tasked with counting several species of animal in aerial photographs. They are difficult to spot and/or determine species so all counting will be done manually. Identified animals may also later be ruled to be a different species than originally assigned, or not an animal at all, so each potential animal must be easily relocated on the photo (individually identified) and a certain degree of flexibility is required. Several people may repeat the count so simplicity is also very helpful.

There may be upwards of 50 individuals in each photo and 3-4 species are possible. I’m working with large (100 Mb) jpegs (composites of several smaller photos) but I can convert them to tiffs if it makes a difference. Anything that I use must be compatible with the Grid plug-in.

The closest plug-in to my needs looks to be Cell Counter. It can assign “types” and the count data can be saved and loaded easily, but it does not count individual objects (i.e. all objects are given a blue 1 rather than blue 1,2,3,…). Point-Picker identifies individual objects but uses colors rather than numbers, while Multi-Point does the individual counting that I need but is not flexible enough if changes need to be made in future (as far as I can tell).

Is there another option that I’ve missed? Is there a straightforward way to modify one of the mentioned plug-ins to do exactly what I need (I of course have little programming experience). Any advice or expertise would be greatly appreciated.

Hello @GMC,

If you use the Cell Counter and click on “Measure…” after selecting all your individual animals, you should have a table with the coordinates of each animal. Moreover, you can simply use the table in a Spreadsheet software to do the counting. Have a look at this example.


I’d like to add to @iarganda’s suggestion that much of the functionality of Cell Counter has been integrated into ImageJ’s own multi-point selection tool. See also this related discussion:

The tool dialog that appears when double-clicking on the multi-point tool will display the number of points for each currently selected class.

1 Like

Hi all. I was wondering if anyone had a solution to how to change the color of individual points in the multi point tool. The points seem to either change color all at once or they change color NOT according to what the color is listed. If I change the selection to red then a gray point shows up on the image. When i chose blue, the point was pink. Green was blue. I’m not colorblind either. If you have any advice then I would appreciate it.

On my system (OS X 10.11) that’s certainly what happens: all points can only be one color. I think it is a limitation of the multi-point tool, unfortunately.

1 Like

Hello! I’m on OSX 10.9.5 and ImageJ 1.5. Not sure if this makes a difference. If you change the counter (double click on the multiple point tool) and change the count to another number and change the color then you can change the colors of the points to have multiple points of different colors. But then the color of the points don’t correspond to what color you selected. Still looking around for other forum posts and playing around with this more. Thanks. Any help appreciated.

Ah, good call. Yes, behavior is the same for me. I edited my post above to avoid confusion. I guess this is probably a bug…

1 Like

The colors of the multipoint tool (when used with multiple counters) are hard-coded in PointRoi.java:

The color choice dropdown menu is ignored in this case. I agree that this is confusing and should be changed e.g. by disabling or hiding the color choice when multiple counters are used. Since this is an ImageJ 1.x function, I guess it is up to @Wayne to change it or not.


The added functionality of ImageJ’s multi-point selection tool is great. I’m trying to incorporate it into a macro that will capture the number of points in each of two classes (Live, Dead).

I found a way to get what I want from a bean shell script with rois.getCounters() (http://forum.image.sc/t/how-to-combine-the-multipoint-tool-and-roi-manager/3075/2), but am not as familiar with writing in bean shell for the rest of my macro. Is there a way to get at the Counter label within the macro language?

If not, I also attempted to evaluate a beanshell script from within a macro that would spit out my counts of each type into a results table. Even though this .bsh script works on its own, within the eval() statement it doesn’t do anything.

eval("bsh","// @ImagePlus imp" +
"import ij.IJ;" +
"import ij.gui.PointRoi;" +
"import ij.measure.ResultsTable;" +
"roi = imp.getRoi();" +
"image = imp.getTitle();" +
"table = new ResultsTable();" +
"if( roi instanceof PointRoi ){" +
"	xpoints = roi.getPolygon().xpoints;" +
"	ypoints = roi.getPolygon().ypoints;" +
"	pointType = roi.getCounters();" +
"	if ( pointType == null ) {" +
"			IJ.error( \"No point types detected! Please use Multi-point tool\" );" +
"			return;}" +
"	counts = new int[ 2 ];" +
"	for( j = 0; j<xpoints.length; j++ ) {counts[ (byte) pointType[ j ] ] ++;}" +
"	table.incrementCounter();" +
"	table.addValue(\"Live\", counts[0]);" +
"	table.addValue(\"Dead\", counts[1]);" +
"	}	table.show( \"CellCounts\" );" );

Any help would be greatly appreciated!

1 Like

Hey All - Does anyone have any updates on this? I am also looking for a way to extract count numbers from the multipoint tool (so I can insert it into the results window with some other data and export it).

Is there perhaps a way to extract the count number from the popup window that appears when you double click the multipoint tool?


Yes, you can grab text from a window using getInfo() and split in a macro like this:
(try it with a multipoint selection active)

myTitle = getTitle(); // read the image name into a variable
run("Properties... ", "show"); //  show the table of point counts (same as alt-Y)
lines = split(getInfo(), "\n");  // store all rows in an array
headings = split(lines[0], "\t"); // store the heading row in an array (optional)
counterValues = split(lines[1], "\t");  // store the counter values in an array

myCounter0 = counterValues[1]; // value of the first counter 
myCounter1 = counterValues[2]; // value of second counter
print(myCounter0,"\n",myCounter1); // print values to the Log window

Slightly easier to manage, the macro below should work IF you don’t also have a regular Results table open. The trick is to rename the Counts table to Results. Then you can use getResult(column, row) to grab the values you need.

run("Clear Results"); // get rid of previous results table
myTitle = getTitle(); // read the image name into a variable
run("Properties... ", "show"); // show the table of point counts (same as alt-Y)
IJ.renameResults("Counts_"+myTitle,"Results"); // make IJ consider this a Results table, so that values can be accessed
myCounter0 = getResult("Ctr 0", 0); // read the value from the first counter, first row 
print(myCounter0); // print the value to the Log window

Hope this helps.


Amazing thanks so much. That works perfectly. I wasn’t familiar with the split function.

Much appreciated!