Dear all, Attached image consists of two open contours. I would like to close these two contours. Please let me know if this is doable in Matlab.
Thanks Ashkan

 채택된 답변

Image Analyst
Image Analyst 2015년 4월 18일

1 개 추천

Skeletonize the blob with bwmorph(), then use bwmorph() again to find the endpoints. Use regionprops() to get coordinates of the skeleton so you know which endpoints belong to the same blob. Then use imline() to draw a line connecting the endpoints of each blob. Demo of imline used to burn a line into an image is attached. Please try these steps yourself first and come back with your code if you can't do it. Again, the rough steps are
bwmorph(binaryImage, 'skel', inf);
bwmorph(binaryImage, 'endpoints');
[labeledImage, numBlobs] = bwlabel(binaryImage);
measurements = regionprops(labeledImage, 'PixelList');
for k = 1 : numBlobs
% find endpoints of this blob, then
imline();
% etc
end
Finish it up (it shouldn't be too hard) and let me know of any problems.

댓글 수: 5

Ashkan Javadzadegan
Ashkan Javadzadegan 2015년 4월 18일
Thanks for this. I ran the first four lines, up to "for" loop, and it returned four end points. However, the loop requires clicking by user to close the contours, but I need it to be done automatically without clicking. I attach herewith my source code and input image. I would be very grateful if you would have a look and let me know.
Paul Simon
Paul Simon 2019년 7월 3일
I'm in a similiar situation. Did you manage to solve it?
Stelios Fanourakis
Stelios Fanourakis 2019년 8월 8일
I do have similar situation. Did you manage to find a solution?
Image Analyst
Image Analyst 2019년 8월 9일
Didn't I outline the solution : use imline() to join the endpoints of each skeleton. Can't you find the endpoints of each blob? Hint: use ismember() or a for loop to find out which endpoints belong to regionprops(k).PixelList().
darova
darova 2020년 6월 25일
i accepted the answer

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

추가 답변 (1개)

Daniel Thomas
Daniel Thomas 2020년 6월 25일

0 개 추천

Don't "burn lines" with imline. Use insertShape instead to draw a line on an image. Additional trouble with insertShape is that it always produces RGB instead of grayscale. So you need to convert it to grayscale. Other than that, it works a lot better than "burning the lines."

댓글 수: 1

Image Analyst
Image Analyst 2020년 6월 25일
It also requires the Computer Vision Toolbox.

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

카테고리

도움말 센터File Exchange에서 Contour Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by