I'm trying to do blob detection on peanut shaped distributions - for a typical example see the image below:
I would like to do find the centroids of the two blobs, but I'm not sure which computer vision methods or algorithms are best to apply to the problem. Ideally the solution should be lightweight, since I need to process many such blobs. So far I've tried using skimage.feature.blob_doh to get the blob center and radius and the finding the weighted mean pixel of that blob, but that hasn't worked very well since blob_doh struggles with the joined nature of the blobs (ie only returns the one blob):
The blobbing code is as follows:
def get_blobs(image, num_blobs):
img = image
img = cv.normalize(img, None, 0.0, 1.0, cv.NORM_MINMAX)
img = img.astype(float)
blobs = blob_doh(img)
ys = np.array([x[0] for x in blobs])
xs = np.array([x[1] for x in blobs])
rs = np.array([x[2] for x in blobs])
sort_args = np.argsort(rs)
xs, ys, rs = xs[sort_args], ys[sort_args], rs[sort_args]
if len(ys) < num_glints:
diff = num_blobs - len(ys)
ys = np.concatenate((ys, np.zeros((diff)))).astype(float)
xs = np.concatenate((xs, np.zeros((diff)))).astype(float)
rs = np.concatenate((rs, np.zeros((diff)))).astype(float)
num_blobs = len(ys)
xs, ys, rs = xs[0:num_blobs], ys[0:num_blobs], rs[0:num_blobs]
return xs, ys, rs
I also don't want to binarize the image, since I am finding the centroid with something like this:
def find_centroid(xs, ys, weights):
sum_w = np.sum(weights)
sum_x = np.sum(np.multiply(xs, weights))
sum_y = np.sum(np.multiply(ys, weights))
cx = sum_x / sum_w
cy = sum_y / sum_w
return [cx, cy]
(in other words, all pixels in the blob contribute to the centroid). Many thanks!

