Perimeter of a specific area?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Steven
il 24 Dic 2013
Commentato: Image Analyst
il 24 Dic 2013
Hi. I want to calculate the perimeter of the object below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/154018/image.jpeg)
I used bwperim to get this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/154020/image.jpeg)
but I really want is indeed the red region specified here (only the arc!):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/154021/image.jpeg)
How I can do so?
Can MATLAB automatically do it or I have to ask the user to select it?
Thanks so much!
Steven
0 Commenti
Risposta accettata
Image Analyst
il 24 Dic 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 Commenti
Image Analyst
il 24 Dic 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?
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!