0

I have a data set of different images. After drawing ellipses, I want to crop them.

I drew ellipses on them. The actual ellipses are the blue ones. The green ones are just how they look like with their angle 0 degrees.

I am using numpy array slicing to get the cropped image:

output_image[y-(minor_axis/2):y+(minor_axis/2), x-(major_axis/2):x+(major_axis/2)]

However the result isn't as it should be. For example the result of the large ellipse looking like an oval is as follows:

I first thought that it is happening because I am using angle during numpy slicing. Therefore, I drew the green circles of angle 0 degree having the same other major axis, minor axis etc values but the result also doesn't correspond to the green circle.

What's going on here?

ali_m
  • 71,714
  • 23
  • 223
  • 298
Black Dragon
  • 147
  • 1
  • 2
  • 13

1 Answers1

0

As far as I can tell from the images and from the single line of code you posted, the problem is that you are not taking the rotation of the ellipse into account.

y + (minor_axis / 2) would only correspond to the top of the cropped region if the minor axis of the ellipse was exactly aligned with the x-axis. However, since your ellipse is rotated by 45 degrees, this is not the case.

You could try to work out the bounding box yourself, based on the parametric equations for an ellipse (see this post for an example). A much simpler option is to let OpenCV do the work, and get the bounding box using cv2.boundingRect, as Miki mentioned in the comments above.

Community
  • 1
  • 1
ali_m
  • 71,714
  • 23
  • 223
  • 298