Seperate out multiple objects considered as single in image - bwlabel

I have a greyscale image and bwlabel() considered intersecting objects as one single region instead of two. I have attached a colour coded output image file. In the attached file on the top left corner, 2 intersecting objects are considered as one, and so on. I was wondering if there was any way to separate them out? I just need to count the number of objects in image. I was thinking of counting the number of endpoints in that particular object to determine the count. eg: if there were 4 corners/endpoints then the count of it is 2.

 Accepted Answer

Try skeletonizing the objects and get the area (number of pixels) of each. If the area is bigger than expected, either throw it out or assume it's 2 intersecting. You can find branchpoints with bwmorph() to split it apart, or if there is no branchpoint, just split it in the middle. For the X you'd have to reconnect one line and throw out the other line.
You can also skeletonize and then count endpoints, both with bwmorph(), as you said. However there might be an occasional object that has 5 endpoints - depends on the shape of the blob.

6 Comments

Thank you so much for your reply!!! The issue is using area to determine the number of objects might not help as there may be more than 2 intersecting blobs in the same area. So I prefer your second option. I have no clue how to implement it though. Could you walk me through it? How do I process bwmorph on the each object returned by bwlabel? I would like to find endpoints of each labeled object and process them. I have attached their outputs.
So far I have tried running it on whole image:
[labeledImage, numberOfObjects] = bwlabel(binaryOut, 8);
BW3 = bwmorph(binaryOut,'skel',Inf);
BW2 = bwmorph(BW3,'endpoints');
imshow(BW2)
This performs on the whole image.How do I break it down? I have attached the corresponding output files.
Then to count the number of endpoints, you can do
numEndPoints = sum(BW2(:));
numBlobs = numEndPoints / 2;
Thanks again for fast response. If you look at the Endpoints Output image attached in previous comment theres more than around 20 endpoints for that blob.The endpoints for even an individual blob without intersection is coming out to be multiple instead of 2 points. Is there any way to work around it?
You can use the 'spur' option of bwmorph to chop off and eliminate small branches that give spurious endpoints.
Hey that didn't help :( . How do I access each blob output of labeledimage and work on it separately? I was thinking of converting each blob output into a line that passes through its middle. Then it would be easier to find the endpoints of that line.
Call regionprops(). That will make measurements of each labeled blob separately.

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!