Can I count different shape with the imageJ?

Hello All,
Could you please assist me to count the different shape from the attach image. I checked different ways but did not find anything like counting specific shape.

Thank you for your time.

1 Like

You can ask ImageJ to give information about the shape when you analyze the particles:

Results are reported as such:

It does not tell you specifically whether something is a square, triangle or circle. You could extract that information yourself from the results based on the reported shape descriptors.

Have a look here for more info:

Thank you for your answer. However, can I make a classifier with weka trainable segmentation and run the image through imageJ. For example, can I defined the shape by adding class and that plugin in run the classifier using imageJ.
Sorry for asking if it is illogical or silly question.
Thank you.

No question is silly :slight_smile:
Have a try at weka with a round, square and triangular class and see how you get on.

That’s a nice intro video.

Thank you for the video. Could you please tell me how can I run the classifier to imageJ.
I made a classifier and data file to analyse. I can load theses files in weka plugin but do you know I can I analyse the image with classifier.

Do you have more information on what you did (screenshot)? What classes did you make? Could you train the classifier? Could you save your classifier? If so, could you then load your saved classifier and apply it to image data? Did anything go wrong there? If so, what exactly?

I tried to make a classifier using weka segmentation tool but it can’t classify the shape of the object. However, I saved the data and .model file but is there anyway to run the classifier and get the results how many of the objects in my images.
However, is there any other way to count the number of object based on color. (see attachment)


I do not think Weka trainable segmentation is the best tool for the first example you presented. If you can segment the object from the background and want to classify based on morphometrical features, the example given by Danielle_Z is the way to go.

IJ does not have a trainable classifier for data in a table. What you then need is to extract the data from the table and create a classifier (eg. k-means or any other) with an external program like Weka (but not the Trainable Weka Segmentation plugin).

Or alternatively you could define a number of constraints that differentiate the objects of interest. This plugin allows you to create some simple classifiers from data in the Results table:
Obviously you need to define from the morphological parameters that you can extract, which combinations enable identification of the objects/classes of interest.

1 Like

Hi gabriel,
I understand the thing but can I ask you is that possible to count the object based on color. Like from the attached image how can I count the number of total image as this is not a binary image?


It is not straightforward to answer such a vague question.
You could define some ranges of colour (e.g. the colour threshold applet might be useful) and process the result with the Particle Analyzer (that will show how many objects were detected at that colour range). Then repeat for all other colours.
But if you do not know how many colours there are or they are not well defined then that will be a further complication.

There is another way of doing this by redirection of a binary image representing all image objects regardless their colour and extract the RGB (or any other colour space) statistics from the original (that is called “redirection” in the Particle Analyzer or the Particles8 plugin) and then process the Results Table data to decide what colour is each object.

You will find that a binary image it is always need. Otherwise is not possible to say which pixels belong to which object or to the background.

I do not think you will be able to do what you want by simply calling an existing IJ command. Macro or plugin writing will be necessary, but before embarking into that, it might be useful to read some image processing book on particle analysis (Russ’ The Image Processing Handbook is a good one).

Thank you for the suggestion and clarification. I will read the book and also available resources to learn more about IJ.

Hi @taufiq_bge

Here is a simple ImageJ/Fiji macro which counts shapes in your image:


For the image you provided, it is possible to differentiate among different shapes based on the circularity of the object (> 0.9 for circle; between 0.78 to 0.9 for square; triangle otherwise). You can play around with these numbers and even use other shape descriptors to extend this macro for shapes different than the ones you have in the image.

Macro could be downloaded from here:

Hope that helps!



Thanks Ved, it worked and easy to understand what you have done in the macros.

Hi Ved,
I am facing a little problem while working with the macro. I made a different shape (attached here). The circularity for circle is 0.907 and triangle is 0.566 (measure the circularity from analyze particles menu). I just omit the square from macros. After running the results showed unusual number of shape.
I changed this part only:

n = roiManager(‘count’);
circles = 0; triangles = 0; //squares = 0;
for (i = 0; i < n; i++) {
roiManager(‘select’, i);
circ = List.getValue(“Circ.”);
if(circ > 0.85)
//else if (circ<0.9 && circ > 0.78)


I will appreciate you help. Thank you.

Hi @taufiq_bge,

I added a line in the code (line 29) and kept the same circularity criteria as before and it works with your new image. It gave me 24 circles, 0 squares and 6 triangles. Check out the macro version 2 at my gist link I posted yesterday.


1 Like

Great to learn from you about imageJ macro. Its really cool. Thanks a lot.

Glad to help you @taufiq_bge !