Count black objects

Tags: #<Tag:0x00007fb882d2f2c0>


the problem of the reflection light produces everytime more or less three white spot on the black objects?
can we identifiy the number of white spot in the black area and then divide them by three to have good estimation of the number of black objects? or would it be to much naive?


There are objects that have 3 points and other 2 points


In a very quick trial using Trainable Weka Segmentation (with the standard settings, and a third class added for the background), I got the following result:

I assume that with some post-processing, it should be fairly easy to filter the objects of interest by size and shape to get a robust count. See also:

The center of cells
The center of cells

You can give me please a link to install Trainable Weka Segmentation ?


I linked it in my post above. Trainable Weka Segmentation comes included with an installation of Fiji:

You can find it using the Command Finder L, or under Plugins > Segmentation > Trainable Weka Segmentation


Good day Emna,

would the following be an acceptable count?

It gives 114 recognized black spheres without using a classifier (weka).

Please be aware that a 100% correct number is generally out of reach.



The center of cells

Yes I can count them manually but I would like to have a function that counts the number of pariculates per color


Good day Emna,

was this a reply to my post?

Actually, the posted image shows an automatically gained result, or at least a semi-automatic one. Depending on the image quality you may have to adjust one parameter.

The approach consists of three steps:

  1. color-threshold
  2. correlation with a prototype sphere
  3. analysis of maxima

Apart from my suggestion I wanted to know what precision of the number estimate is required.




Dear Herbie,

would you mind explaining step 2 in more detail?

Thank you,


Good day Martin,

well, with correlation I evidently mean the computation of the cross-correlation function.

It’s just the same as e.g. searching all positions of letter “e” in a text page, provided you have one letter “e” of the correct font available as an image.

ImageJ can compute the cross-correlation function of two images (e.g. the text page and the prototype “e”) via complex-valued multiplication in the Fourier-spectral domain. As always, a look at the relevant pages of the manual reveals more details:
(especially: 29.10.7 FD Math… )




How about just blurring the shine? This gives me 128. Herbie’s method is probably more robust though.

Gaussian blur 3, Color threshold, find maxima


Dear @Emna,

I have just thresholded with the default method of ImageJ the image and set some area constraints to the object to find (i.e. 20-100) with Analyze Particles tool.
Then, supposing that the great majority of the black balls have 3 bright spots I divided the number of ROIs by 3.
I found 373 ROIs /3 = 124 black balls; this number is more or less comparable to the number other has found with other methods.
So now you’ve a lot of methods and approaches to test.

I compared them to a count of them done by hand (points in green on the below image)

by hand (by my hand :wink: ) they are 137.
So it obviously underestimates, but it is not so bad.

As many of us pointed out to you it would be kind by you tell us how much precise you want the estimation of the number of black balls.

But ok, we really don’t know if you are still reading us trying to help you;)

have a nice day,
Emanuele Martini


I do not have an estimate of number but I always try to see is what the count could detect all the particles or not


Excuse me for the delay. Thank you very much for your help emartini and especially for the time you spent. I will try this method because if there is a 10 difference it is not a problem


ok @Emna,
nice! :wink:
let me know if it works fine and if you have some “implementation” problems.

have a nice day
Emanuele Martini


Yes, I have a question, how could you detect only the white spots? Because if I put in circularity 20-100 it will detect all the particles


It’s not the circularity but the size to set 20-100 :slight_smile:
I think you can leave circularity 0-1 .


Okay. And when I use analyze particles it asks me before turning the image into binary ( ie black and white). How you kept it in gray scale without transforming it?


Dear Emna,
just to be clear we are doing the same :smiley: I will put a step-by-step protocol to analyse your image:

  1. open the picture
  2. convert to 8bit (Image->type 8bit)
  3. set the pixel calibration properly from Image->Properties you will set 1 pixel is 1 pixel.

so now you will have a gray picture with the calibration in pixel on the top part of the picture you must have 598X897 pixels

  1. set the threshold with Image->Adjust->Threshold and I keep the Default method, but maybe you can try someone else: don’t click apply keep it with the red (you can set it in the threshold tool selecting red).

  2. now you can analyse particles with Analyze-Analyze Particles…
    usually I just add them to manager and if you want you can directly add to the Results Table (just pay attention when you repeat the analysis with another picture to delete previous rois and results to don’t count them double times)

*the black balls will be 373 (the number of measurements/rois you) have divided by 3 rounded up -> 373/3 = 125 *

Hoping that is clearer and helpful
have a nice day
Emanuele Martini


then of course you can also fine tune some parameters like the threshold methods or value and the size constraints…
like maybe you can put 10-100 in the size
but you will have to test them and for sure sometimes to be more confident with the analysis count them by hand.