Reputation: 91
So I have the above contour and I want to plot a Major Axis and Minor Axis Line of the contour, what I do is exactly like this
s=regionprops(image,'Centroid','Orientation','MajorAxisLength','MinorAxisLength');
xMajor=s.Centroid(1) + [-1 1]*(s.MajorAxisLength/2)*cosd(s.Orientation);
yMajor=s.Centroid(2) + [-1 1]*(s.MajorAxisLength/2)*sind(s.Orientation);
xMinor=s.Centroid(1) + [-1 1]*(s.MinorAxisLength/2)*sind(s.Orientation);
yMinor=s.Centroid(2) + [-1 1]*(s.MinorAxisLength/2)*cosd(s.Orientation);
line(xMajor,yMajor);
line(xMinor,yMinor);
but what I get so far is the picture below
am I doing it wrong? Thanks in advance.
Upvotes: 2
Views: 1851
Reputation: 5188
For the minor axis, the orientation is s.Orientation+90
, so cosd(s.Orientation+90) = sind(s.Orientation)
but sind(s.Orientation+90) = -cosd(s.Orientation)
.
So you have to use:
xMinor=s.Centroid(1) + [-1 1]*(s.MinorAxisLength/2)*sind(s.Orientation);
yMinor=s.Centroid(2) - [-1 1]*(s.MinorAxisLength/2)*cosd(s.Orientation);
Upvotes: 3