Counting eggs with analyze particles but does not recognize all eggs

I want to count mosquito eggs using ImageJ instead of by hand, however I can’t seem to get the settings right. I already googled and checked some other topics, sorry if one has not caught my attention yet!

Some background information:
I use Windows 10. I am taking a picture with a simple compact camera, mostly 1x or max 2x zoom in the same tube. Mosquito eggs from the Anopheles genus are dark, small ellipses that are scattered over the water surface. I am taking a picture on a white surface but some dark stains from the mosquito are also in the water.
This is how I get my picture out of the camera:

I cropped it and tried to remove the stains by painting them white by hand (but preferably I would not do that since I have many pictures).

The main problem with my masks is that these eggs can lay pretty closely together and therefore do not seem to be recognized anymore. Below I have an example, where only 38 out of the 74 eggs are counted. You can see that the clumps of eggs are missed.

Thresholds seem to be sufficient but it cannot translate all separate eggs. For instance, the Y-shape at the bottom right is 4 eggs in total.

Attached another picture of a raw image just in case (the one from the Y shape).

I don’t know how to copy a whole timeline in here, sorry, but I hope that my current information is sufficient…

Please let me know if there are any questions or if anything’s unclear! I’m looking forward to your feedback on how to use this.

Hello Anopheles,
It might help you considerably to convert the image to something like 32bit. Use Image>Type>32bit, then use a LUT (color map) such as 16 colors. This should give you a better eye, and set you up to segment and count them.

You do not get the clusters of eggs because you are specifying a given range for circularity in the dialog. The clusters have low circularity and so they are left out.

1 Like

Does this can help you out with what you want ?Mosquito eggs.txt (339 Bytes)
run(“Duplicate…”, " ");
setOption(“BlackBackground”, true);
run(“Convert to Mask”);
run(“Analyze Particles…”, “size=40-Infinity display summarize add”);
roiManager(“Show All without labels”);


Hello smith_robertj,

Thanks for your reply. I played around with converting the image, ranging from 8bit to 32 bit, but it does not help immediately. I tried setting up a LUT with 8 colors but there does not seem to be a color in between the two eggs sometimes. How can I use my LUT to segment and count the eggs? I’m still an ImageJ beginner so sorry for any stupid questions!

Hi gabriel, thanks for pointing that out. However, I still want to count the individual eggs, not just a whole clump so that is why I specified circularity. When removing the circularity it recognizes some clusters but of course does not count the eggs inside them but counts one cluster as one egg. Do you have any recommendations on how to solve this?

Hi Anophèle
Here is a picture on which I counted 63 eggs.

Is it okay? Follow the macro. Line by line.20191105_Mosquito eggs-1.tif (2.7 MB)

Hi Mathew,
Thank you so much for the script! Sorry for my late reply, it took a while to figure out how to run the macro. I had not heard of watershed before but this really seems like a useful plugin.

The image has 78 eggs and not 63 but it is definitely better than before! Do you have any suggestions on how to go the extra mile and separate/count the other eggs as well?

Well you cannot have it both wasy by rejecting the clustered objects and also counting them.
My suggestion would be to detect all blobs, then partition the clusters that need partitioning into individual objects, but that is quite a complex problem. The solution posted above does not resolve it properly either.
Have a look at this paper:

1 Like