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":
For two overlapped "blobs":
For seven overlapped "blobs":
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;
- Download and install ImageJ.
- Load your image file (drag and drop the image to ImageJ menu bar).
- Make it binary (0,1) image
Process | Binary | Make Binary
- Break-apart (isolate) fused particles.
Process | Binary | Watershed
. - Count particles by
Analyze | Analyze Particles
.(minimum size~ 500 pixels) - AS the process (3) flips black/white, you may want to reverse the B/W back to original by
Edit | Invert
.