What coordinate system does regionprops assume for orientation angle?
5 views (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
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.
More Answers (0)
See Also
Categories
Find more on Hamamatsu Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!