What coordinate system does regionprops assume for orientation angle?

5 views (last 30 days)
Hello,
I've been using regionprops to query the centroid and orientaiton of ellipses fitted to thresholded image data. The centroid that the function returns seems to correspond to the image coordinate system (origin at top left, x to the right and y down) while the orientation angle returned seems to assume a standard coordinate system (x to the right and y up).
To demonstrate my question, I've used regionprops to return the centroid and orientation of an ellipse fitted to the following image:
Using the following code, I plot the centroid and the major axis of the ellipse fitted to the region:
load BW.mat;
s = regionprops(BW,{'Centroid','Orientation','MajorAxisLength','MinorAxisLength'});
imshow(BW);
hold on;
%Plot centroid
plot(s.Centroid(1),s.Centroid(2),'r*'); %Centroid is in correct location
%Create unit vector pointing in direction of ellipse major axis
angle = s.Orientation*pi/180;
u = [cos(angle) sin(angle)];
%Plot major axis
majAxis = [-s.MajorAxisLength/2*u(1) -s.MajorAxisLength/2*u(2);
s.MajorAxisLength/2*u(1) s.MajorAxisLength/2*u(2)];
majAxis = majAxis + s.Centroid;
plot(majAxis(:,1),majAxis(:,2),'r'); %Major axis is incorrect
This results in the following image:
If I flip the sign of the angle returned by regionprops, the axis is aligned correctly as in the following code/image:
load BW.mat;
s = regionprops(BW,{'Centroid','Orientation','MajorAxisLength','MinorAxisLength'});
imshow(BW);
hold on;
%Plot centroid
plot(s.Centroid(1),s.Centroid(2),'r*'); %Centroid is in correct location
%Create unit vector pointing in direction of ellipse major axis
angle = -s.Orientation*pi/180; %Multiply the returned angle by -1
u = [cos(angle) sin(angle)];
%Plot major axis
majAxis = [-s.MajorAxisLength/2*u(1) -s.MajorAxisLength/2*u(2);
s.MajorAxisLength/2*u(1) s.MajorAxisLength/2*u(2)];
majAxis = majAxis + s.Centroid;
plot(majAxis(:,1),majAxis(:,2),'r'); %Major axis is correct
If I'm understanding this correctly, s.Centroid uses the image coordinate system while the orientation needs to be flipped to correspond to a positive rotation in that coordinate system. Is this an inconsistency in the behavior of regionprops or am I missing something?
Thank you!

Accepted Answer

Matt J
Matt J on 20 Mar 2025
Edited: Matt J on 20 Mar 2025
You can still view the Orientation properties coordinate system as x-right, y-down, z-into-screen. However, the direction of positive Orientation must be interpreted as clockwise about the z-axis, not counterclockwise.
Altternatively, you could interpret the z-axis as oriented out-of-screen and the Orientation angle as positive for counter-clockwise rotations around that. Admittedly, this gives you a non-righthanded system.
  4 Comments
Image Analyst
Image Analyst on 21 Mar 2025
Note: you can use cosd and sind to input angles directly in degrees. No need to multiply by pi/180:
angle = -s.Orientation; % Multiply the returned angle by -1
u = [cosd(angle), sind(angle)];
Stephen
Stephen on 21 Mar 2025
Ah thats true- working in radians is a deep habit at this point, I didn't even think twice about it!

Sign in to comment.

More Answers (0)

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!