The Problem :Finding the number of occurrences of a certain pattern (or shape) in an image. In my example, the problem is about finding the number of spots (in variety of sizes) in an image. See figure 1 below:What I'm looking for here is an orientation. What class of algorithms can lead to a solution for this type of problems? 
Which algorithm for counting the occurrences of a certain pattern (spots) in an image?
machine learning;image processing;computer vision;pattern recognition
The best way to get an orientation is to read a textbook on computer vision or image processing.  There are lots of techniques known, and that's often the best way to get an introduction to a broad topic like this.Anyway, for some specific techniques, I would recommend that you learn about the following candidate approaches:Learn about morphological operators, and experiment with a few combinations of them.Learn about the watershed transform, which might solve your problem immediately.  More generally, learn about image segmentation techniques, of which there are many.You might want to consider applying thresholding to the image as a pre-processing step.Your task looks pretty easy, so I imagine you should be able to find a very effective combination of techniques if you learn about them and try them out on sample images.