Use a paint-bucket fill algorithm -- there's plenty to find on the web. Scan the image for the first coloured pixel you find, do a paint fill to get all the connected pixels, add 1 to your shape count and delete those pixels. Repeat until there are no coloured pixels left. Or does this count as brute force?

BB