Detecting overlapping blobs in image?

I tried out an algorithm based in azimuths and second derivatives, by using contours circulars, and it works well. PyQGIS code is as follows:

layer = iface.activeLayer()

feat = layer.getFeatures().next()

points = feat.geometry().asPolyline()

azimuths = [ points[i].azimuth(points[i+1]) for i in range(len(points)-1) ]

az_diff = [ azimuths[i+1] - azimuths[i] for i in range(len(azimuths)-1) ]

sum = 0

for item in az_diff:
    if item < 0:
        sum += 1

blobs_number = sum/2 + 1

print 'blobs_number: ', blobs_number 

For one circular "blob":

enter image description here

For two overlapped "blobs":

enter image description here

For seven overlapped "blobs":

enter image description here

Results were as expected.


I am aware you already found the solution, so this is just for future reader (if any) who might be interested in. (As this can also be seen as an image processing).

In bio and medical area, ImageJ is well-know for such a task. Not frequently, but there are some discussions in this forum with subjects related to remote sensing.

Using ImageJ workflow would be;

  1. Download and install ImageJ.
  2. Load your image file (drag and drop the image to ImageJ menu bar).
  3. Make it binary (0,1) image Process | Binary | Make Binary
  4. Break-apart (isolate) fused particles. Process | Binary | Watershed.
  5. Count particles by Analyze | Analyze Particles.(minimum size~ 500 pixels)
  6. AS the process (3) flips black/white, you may want to reverse the B/W back to original by Edit | Invert.

enter image description here