MATLAB: Perimeter of a specific area

perimeterspecific region

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

Best Answer

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.