Rotate an object based on regionprops Orientation - explanation

4 views (last 30 days)
Hi,
Based on this question (https://www.mathworks.com/matlabcentral/answers/2034614-rotate-an-object-based-on-regionprops-orientation-minferet-and-maxferet-angles), can someone please explain me or give me a reference to understand the orientation based calculation:
hlen = st.MajorAxisLength/2;
xCentre = st.Centroid(1);
yCentre = st.Centroid(2);
cosOrient = cosd(st.Orientation);
sinOrient = sind(st.Orientation);
xcoords = xCentre + hlen * [cosOrient -cosOrient];
ycoords = yCentre + hlen * [-sinOrient sinOrient];
Furthermore, why hlen (MajorAxisLength/2) is needed to draw the line ? Is there a way to do it without MajorAxisLength?
Thanks

Answers (1)

Image Analyst
Image Analyst on 6 Nov 2023
The "angle" of an irregularly shaped object is not a clear cut definition. As you can imagine, the angle you get from the max Feret distance could be different than you'd get from regionprops, which fits the boundary to an ellipse and returns the angle of the ellipse in degrees.
The major axis length is the length from one end to the other, hence it encompasses the centroid. If you want to plot the fitted ellipse that was found, you need to draw it from the origin/centroid. As you know from the simple example of drawing a circle, you use the radius (half the max diameter), not the full diameter.

Tags

Community Treasure Hunt

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

Start Hunting!