Home > Net >  Code not displaying major and minor axes over image
Code not displaying major and minor axes over image

Time:11-05

I am using the following code:

   majors = cell_props.MajorAxisLength;
   minors = cell_props.MinorAxisLength;
   ctr = cell_props.Centroid;
   theta = cell_props.Orientation;

   imshow(cell_full)
   hold on

   for k = 1:length(measurements)

       xMajor=ctr(k,1)   [-1 1]*(majors(k)/2)*cosd(theta(k));
       yMajor=ctr(k,2)   [-1 1]*(majors(k)/2)*sind(theta(k));

       plot(xMajor,yMajor,'r','LineWidth',2);

       xMinor=ctr(k,1)   [-1 1]*(minors(k)/2)*sind(theta(k));
       yMinor=ctr(k,2) - [-1 1]*(minors(k)/2)*cosd(theta(k));
   
       plot(xMinor,yMinor,'b','LineWidth',2);
   end
   hold off

My image is: Original Segmentation

When I try to run the code previously mentioned, for some reason it creates these lines: Major and Minor Axes

I realize I am probably doing something wrong with the math here, but I am not sure what. I have tried converting theta to radians, switching the minor coordinates and major coordinates for the lines. Nothing seems to work.

Any help would be appreciated.

CodePudding user response:

As Christoph pointed out in his comment, the axes ought to be reflected vertically. This means the positive direction of orientation angle is wrong. A negative sign in front of theta(k) should fix it.

xMajor=ctr(k,1)   [-1 1]*(majors(k)/2)*cosd(-theta(k));
  • Related