I want to count the max tiles of the same color in picture as below, for this picture, the right result should be as below, how can I get a algorithm to calculate this?

pink=6, green=5, blue=2, yellow=1

How to count tiles of same color?-tile.jpg