What coordinate system does regionprops assume for orientation angle?

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

Thanks for the response! I thought that might be the case, but I wanted to make sure that I wasn't making a mistake or wrong assumption. I know it's a minor/specific problem to have, but would it be appropriate to suggest revising the documentation to be more specific about what constitutes a positive angle when using regionprops?
It suspect if you report it to Mathworks, they will be receptive.
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)];
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

Asked:

on 20 Mar 2025

Commented:

on 21 Mar 2025

Community Treasure Hunt

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

Start Hunting!