Separating intersecting blobs on an image

I am doing a project in Digital Image Processing where I am segmenting images which have multiple cells, many times these cells touch. I have succeeded in separating the background as shown in attached image "BW200.png". I want to separate them, so I tried using the Watershed algorithm(refer attached image "watershed200.png"), but the algorithm is segmenting the image too much and I must be able to know which slices to merge to get the desired cell. So I was wondering if there was a way to identify the centroids of the blobs in the image using which I can find out the approximate shape of each blob and merge the appropriate slices on the watershed. The final goal is to obtain something like the attached image "separated.png"(Coloured in photoshop). What do you suggest I do?
imshow(imread('separated.png'))

 Accepted Answer

This uses some tools downloadable from,
load BWimage
BW=imresize(BW,'Output',[500,500]);
BW0=BW;
BW=~bwlalphaclose(~BW,20);
BW=bwareafilt( imfill(BW,'holes') ,5); %5 is the number of principal, large blobs
L=bwlabel(BW);
L=geodesic(BW0,L).*BW0;
L(BW0 & ~ L) = max(L(:))+1; %Assign a common label to small left-over blobs
h=imshow(labeloverlay(uint8(BW0)*255,L)); shg
function nearest=geodesic(BW,L)
%Finds the geodesically nearest blob to any true pixels in BW
%not yet labeled in L.
M=max(L(:));
D = nan([size(L),M]);
for i=1:M
D(:,:,i) = bwdistgeodesic(BW,L==i);
end
[val,nearest]=min(D,[],3);
nearest(val==inf)=0;
end

5 Comments

Thanks a lot!!
I've edited my answer to give what I think is a somewhat more natural segmentation.
Oh I had already kind of done something similar myself, what I had done was use the alphaclosed image that showed the blobs eroded forms, used bwconncomp on BW0 and eliminated all components that have no overlap with the alphaclosed image, it worked quite well. I just tried your solution on it and it has similar effects.
This was my solution:
This is your solution:
Your solution seems to be wroking better. The main problem I am facing with this solution is that in this particular image the blobs connected to the central cell are big enough so alphaclosing it with alpharadius 20 separates them sucessfully. But in another image where the connected blobs are small, it gets eroded too much and the connected blob gets eliminated in the alphaclosed image, hence the whole connected blob gets labelled as the central cell.
and the bottom left blob keeps getting eliminated in alphaclose untill the alpharadius is reduced from 20 to 4, at which point though the alpha eroding is too less and the other blobs label gets merged with the main one as can be seen below.
So while the bottom left blobs are connected to the main cell, they are connected by a very small margin which can be handled by a very small alpharadius, but the other blobs require higher alpharadius, the lowest I checked with this image is with alpharadius 7 which still labels the other blobs other than the bottom left ones correctly as can be seen below:
But in the first picture alpharadius of atleast 13 is required, lower than 13 and the right blob merges with the main as can be seen below.
So the overall result should be better if I reduce the alpharadius to about 13 but still there will be some slides where small interconnected blobs will get merged. Trying to see if I can improve any of that.
Maybe once you've done the initial segmentations above, you can subsegment the central blob with the same routine, but with a larger alpha radius.
When successfuly segmented, the central blob always seems to have an Eccentricity of less than 0.5, and otherwise jumps significantly. So maybe you can use that as a criterion to subsegment.
load L
regionprops('table',(L==3),'Eccentricity')
ans = table
Eccentricity ____________ 0.43298
regionprops('table',(L==3)+(L==4),'Eccentricity')
ans = table
Eccentricity ____________ 0.65189
Thats a great idea, will be trying it, will update you when I do

Sign in to comment.

More Answers (0)

Asked:

on 21 Apr 2025

Commented:

on 23 Apr 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!