# Counting tablets

I have developed a pill counter. It uses something similar to this tutorial and to this tutorial

However (as the next step) I want to count also tablets such as:

Although the segmentation process is a bit complicated (because of the semi-transparency of the tablets) I have managed to get this

My problem is here. How can I count the elongated tablets, separating each one from the image, similar to the final results in the linked tutorials? I would appreciate if someone can help me to find a solution. So far I have applied distance transform, then smooth it with a Gaussian filter and then watershed and I got

As you can see, it does not work well, specially for adjacent tablets.

The solution does have to work for this image and also for other arrangements of the tablets, the most difficult being for example

Thank you very much for any pointer or help on how to solve this problem. (My project has to address more complicated problems too, but would like to start with this)

really interesting topic. I'm thinking if some iterative closest point methods can handle this or not.

Could you specify one example of these methods so that I can investigate further from there?

don't know if it work or not, I just thinking if you can use some template of points from a single pill and match it one by one like https://github.com/abreheret/icp-opencv

It is common in biological image that the objects may be in any angle and may overlap , I'm surprising that there are so few of rotation invariant algortihm can doing fine job in these issue after doing a little survey .