How to close boundary of a circular object in binary image

조회 수: 6 (최근 30일)
CW Hsu
CW Hsu 2022년 11월 29일
댓글: CW Hsu 2022년 12월 9일
Thank you all for being here.
I have an image below
the outer boundary is not closed. So it would be a problem when I calculate area of this bubble.
How can I close the boundary of circular object in image above image automatically?

채택된 답변

Matt J
Matt J 2022년 11월 29일
load Image
[c,r]=imfindcircles(BW,[10,100]);
area=pi*r^2
area = 1.1299e+03
  댓글 수: 5
Matt J
Matt J 2022년 12월 1일
편집: Matt J 2022년 12월 1일
Use a loop over the different detected circle data c(i,:) and r(i) to repeat the process for many objects.
CW Hsu
CW Hsu 2022년 12월 9일
Thanks for your help. It works successfully

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 11월 30일
Try this, where mask is your binary image
mask = bwconvhull(mask, 'union');
props = regionprops(mask, 'Area', 'EquivDiameter');
area = props.Area
diameter = props.EquivDiameter
  댓글 수: 2
CW Hsu
CW Hsu 2022년 12월 1일
@Image Analyst Thanks for your advice.
Since I have many images, usually there is not only one circular object in the image. Can I use 'union'? Or maybe 'object' ?
But for the image I show at the top. I try using 'object' . The image becomes image like this.
Image Analyst
Image Analyst 2022년 12월 1일
You can use the 'objects' option but keep in mind that if the curves are too far apart it will consider them as two separate blobs. So two C shapes might end up as two solid D shapes. Only if their convex hulls overlap would they be considered a single blob. And then you might get something like your bottom image. So you'd have to call bwconvhull a second time to get a convex shape.
Another option would be to use dbscan to identify which pixels are close to each other. You specify that closeness distance. So this essentially labels each group of blobs with a single ID number. Then you can use ismember to extract each group one at a time, and then use the 'union' option since all pixels in the image now belong to a single group. Then repeat for all groups in the image. I'm attaching a demo I created of dbscan. See Wikipedia if you don't know what dbscan is.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by