Perimeter of a specific area?

6 views (last 30 days)
Steven
Steven on 24 Dec 2013
Commented: Image Analyst on 24 Dec 2013
Hi. I want to calculate the perimeter of the object below:
I used bwperim to get this:
but I really want is indeed the red region specified here (only the arc!):
How I can do so?
Can MATLAB automatically do it or I have to ask the user to select it?
Thanks so much!
Steven

Accepted Answer

Image Analyst
Image Analyst on 24 Dec 2013
First of all, invert and call bwareaopen() to get rid of the small specks, then invert to get back the original again. Then you can get a perimeter without the little noise bits.
But I wouldn't use bwperim because I'd want the boundary coordinates in order so I can find the kinks. So I'd use bwboundaries() to get the x,y coordinates in order as it goes around the curve.
Then you can use Roger Stafford's kink finding code in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_find_.22kinks.22_in_a_curve.3F to find the 3 "kinks" in your curve. Once you know that, you can split up the boundary coordinates into 3 segments. Of course one of them will be on each end of the array. So you'll have (part of segment1),(all of segment2),(all of segment3),(remaining part of segment1) as you traverse the boundary coordinates. Does that make sense. Finally, for robustness you'll have to check for the case where a kink pixel lies exactly at the first coordinate. That's not too likely but if you want bulletproof code, you need to check for it and be prepared to handle that case.
  4 Comments
Steven
Steven on 24 Dec 2013
Edited: Steven on 24 Dec 2013
Thanks again. I did so but I did not understand these three segments you mentioned and how to handle them is difficult.
Also I used bwperim since you kindly suggested to me somewhere else:
But since I have too many different cases, I am not sure how to deal with them all, so that as you said I can have a bulletproof code.
I will ask another question for this general case and would be grateful for your answer.
Thanks.
Image Analyst
Image Analyst on 24 Dec 2013
Well, you just have to decide on a case by case basis whether you want to use bwperim or bwboundaries. I use both depending on which seems better and easier.
Now the boundary is a list of (x,y) coordinates, right? And you have 3 segments, right? The two straight ones and the curved one. So what happens if the list of coordinates starts right in the middle of one of the segments? Well, that segment would be split into two, one for the start of the coordinate list, and the remainder would be at the end of the coordinate list. Does that explain it better?

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!