[GIS] Detecting overlapping blobs in image

imageopencvpython

I have read the following two posts related to my question; however, my problem is slightly different and I'm having a hard time solving it.

  1. Finding if two polygons Intersect in python?
  2. Getting intersection of circles using shapely?

I have an image with irregular shapes such as these: enter image description here

Now, with this image, I'd like to be able to identify the separate blobs, even if they're adjoined. In particular, I want to count individual blobs that are tightly overlapping. Like for instance: enter image description here
For instance, in that image, I want to be able to count 7 separate blobs. However, edge detection only counts 1. If I use some solidity cutoff (area of blob/area of convex hull), I'm able to count 2.

I'm not so concerned about the separate non-overlapping ones. But I'm having a really hard time detecting them using edge detection. I tried using Opencv's Canny function and HoughesCircles function. Neither of them proved effective.

Any idea how to proceed?

Best Answer

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.

Related Question