the algorithm Joachim is speaking about is called connected components labelling. You can find pseudo code and some implementation at the following url :
Dinesh can u advise in detail which morphological operator can be used here. Since the background of the small circles are both white (immediate background) and black pixels. I am unable to use it.
Depending on the image , you should also try applying some low level preprocessing - smoothing or so to remove any pixels that would break the objects.
Martin U can see in my image the circular objects in the center have immediate neighbors as white pixels. But again beyond white pixels I have black pixels. So i could not understand how can I have the access over the center circles. I desire if by some means I can assign the outer black pixels as 1 or make them white then I can count the circles. But I am unable to do that.
you could also use - considering that your regions are separated and the inside of the circles are homogeneous, a hierarchical region growing. Essentially, start with a region growing at random location x,y - when finished remove it and start on another location x,y. until all the image has been processed. Then - assuming that you can distinguish what is back ground and what is foreground you can count the number of black regions.
Before labeling you indeed need to segment in two phase your image. In the case of this image it is really straightforward otsu method for instance will work perfectly. Then you apply labelling on the segmented image. If you use matlab it can be written in two lines of code ;
level = graythresh(I);
BW = im2bw(I,level);
output=bwlabel(BW, 8);
if you just need the number of object it is given by max(max(output))
U can see in my image the circular objects in the centre have immideate neighbors as white pixels. But again beyond white pixels I have black pixels. So i could not understand how can I have the access over the center circles. I desire if by some means I can assign the outer black pixels as 1 or make them white then I can count the circles. But I am unable to do that.
Or by some means if I can label the centre pixels with an integer other than 0.
Using the above matlab I am getting the output as 2 however it is not correct
You can simply run blob analysis function and get the count of blobs returned. If you are using OpenCV, you can add the library cvBlobslib and it is a simple function call after that.
blobs analysis can work well, but the image is a bit confusing though, because if we are talking about the black holes in the middle we need to remove the black background first. and if we need to consider the white object, then we need first to apply hole filling algorithm
I know this is an old thread, but if you are still having issues. I would definitely recommend you visit www.MIPAR.us. This is something it is perfectly suited for, and so much more.
It is very powerful and intuitive 2D/3D image analysis software written by scientists/end-users and is about to be released as a free trial on December 14th. You can sign up on the site as well as submit images/datasets to test.
There are many image analysis options available, but I think you may just find MIPAR to be something special if you give it a try!