Looks like you should use Particle analysis/detection within each of those tablets. Firstly, to identify the tablets, you should again use particle analysis/detection.
The open source software ImageJ has code for this - see
Particle Analysis[
^]
You can find source code for ImageJ (is in Java) at their site, or on Github. You'll need to examine the code which does this, and port it to the language you need.