How to visualize MajorAxisLength and MinorAxisLength on images?

Hi,
I would like to replicate something similar to that shown in the explanation of "Orientation" property of the "regionprops" function, as viewable here:
I would plot the red ellipse and the blue lines representing the axes, over my images (both binary and grayscale). I found this example:
but I can't understand how complete the code to plot the blue lines. Could anyone help me, please?
Thanks for your answers.

 採用された回答

Image Analyst
Image Analyst 2016 年 7 月 12 日

1 投票

Get the two endpoints of the line, then call plot. For example x1 = xCentroid + (majorAxisLength/2) * cosd(orientation). Same for y1, x2,and y2. It's just simple trigonometry. Then call plot([x1,x2], [y1,y2], 'r-').

4 件のコメント

Image Analyst
Image Analyst 2016 年 7 月 12 日
Note that the ends/tips of the major axis don't usually lie on the perimeter. If you want/need that, see my attached demo.
Nut
Nut 2016 年 7 月 12 日
You're right, it was very simple but I didn't see the solution, I don't know why!
About the ends of the axis, I already know they don't usually lie on the perimeter, but it is not an issue in my work, I have not to plot the axes so precisely. Anyway, your demo is very interesting, I'll keep and try it.
Thank you very much!
hu
hu 2018 年 1 月 14 日
Is it possible to modify the code so I can see how to run it on image contain several objects (like rice.png)?
Thanks a lot.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

Nut
2016 年 7 月 12 日

コメント済み:

2018 年 1 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by