how can we separate between two shapes overlapping in an image?

4 views (last 30 days)
we have an image with two kinds of shapes- spheres and rods. we need to classify them.there are some particles overlapping, how can we distinguish between them?
here is the code:
% load the image im = imread(fullfile(DataFolder,imName));
im = double(im);
% displays the image
subplot(2,2,1);
imagesc(im);
fgIm = im<=130;
% clean foreground
se = strel('disk', 4); %# structuring element
fgImClean = imopen(fgIm,se);
subplot(2,2,2);
imshow(fgImClean);
axis equal;
hold on;
f = double(fgImClean);
props = regionprops(fgImClean,'MajorAxisLength','MinorAxisLength','Area','Centroid','Perimeter');
props = props([props.Area]>1000);
centroids = reshape([props.Centroid],2,[])';
aspectRatio = [props.MajorAxisLength]./[props.MinorAxisLength];
classB = aspectRatio>1.5;
classA = ~classB & ([props.Area]./[props.Perimeter])>(.3*[props.MajorAxisLength]/2);
classC = ~classA & ~classB;
plot(centroids(classA,1),centroids(classA,2),'+r');
plot(centroids(classB,1),centroids(classB,2),'+b');
plot(centroids(classC,1),centroids(classC,2),'+g');
the code suppose to mark spheres in red, rods in blue.
we attached a picture as an example
thank you.

Accepted Answer

Image Analyst
Image Analyst on 7 Apr 2014
You can't in general. For example what if they overlap entirely like a small circle inside a rod or a bigger circle. What you can do is to measure the circularity (= perimeter^2/(4*pi*area)) or solidity and throw out blobs that aren't rods or circles. Try to get better images by having better dispersal of the particles. Maybe dilute the solution or something.
  3 Comments
Image Analyst
Image Analyst on 7 Apr 2014
You might try imfindcircles() and see what that picks up. If the circle is different enough in diameter than the radius of the rod you might be able to get the circles. If all the rods are the same size, and you've removed the circles, then you can look at the area of the irregularly shaped blobs to estimate about how many rods might be contained in it. Of course that's just if you want a count, not a size distribution, because if you don't know the size distribution, you can't estimate how many rods are in a blob.
Inna
Inna on 7 Apr 2014
it was very helpful! we just need to count the rods.
thank you.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!