otx.api.entities.shapes.ellipse#

This module implements the Ellipse shape entity.

Classes

Ellipse(x1, y1, x2, y2[, modification_date])

Ellipse represents an ellipse that is encapsulated by a Rectangle.

class otx.api.entities.shapes.ellipse.Ellipse(x1: float, y1: float, x2: float, y2: float, modification_date: datetime | None = None)[source]#

Bases: Shape

Ellipse represents an ellipse that is encapsulated by a Rectangle.

  • x1 and y1 represent the top-left coordinate of the encapsulating rectangle

  • x2 and y2 representing the bottom-right coordinate of the encapsulating rectangle

Parameters:
  • x1 – left x coordinate of encapsulating rectangle

  • y1 – top y coordinate of encapsulating rectangle

  • x2 – right x coordinate of encapsulating rectangle

  • y2 – bottom y coordinate of encapsulating rectangle modification_date: last modified date

denormalize_wrt_roi_shape(roi_shape: Rectangle) Ellipse[source]#

Transforming shape from the normalized coordinate system to the roi coordinate system.

This function is the inverse of normalize_wrt_roi_shape

Example

Assume we have Ellipse c1 which lives in the top-right quarter of the normalized coordinate space. The roi is a rectangle living in the half right of the normalized coordinate space. This function returns Ellipse c1 expressed in the coordinate space of roi. (should return top-half)

Ellipse denormalized to a rectangle as ROI

>>> from otx.api.entities.annotation import Annotation
>>> from otx.api.entities.shapes.ellipse import Ellipse
>>> c1 = Ellipse(x1=0.5, x2=1.0, y1=0.0, y2=0.5)  # An ellipse in the top right
>>> roi = Rectangle(x1=0.5, x2=1.0, y1=0.0, y2=1.0)  # the half-right
>>> normalized = c1.denormalize_wrt_roi_shape(roi_shape)  # should return top half
>>> normalized
Ellipse(, x1=0.0, y1=0.0, x2=1.0, y2=0.5)
Parameters:

roi_shape – Region of Interest

Returns:

New polygon in the ROI coordinate system

get_area() float[source]#

Computes the approximate area of the Ellipse.

Area is a value between 0 and 1, computed as pi * vertex * co-vertex.

>>> Ellipse(x1=0, y1=0, x2=0.8, y2=0.4).get_area()
0.25132741228718347
Returns:

area of the shape

get_evenly_distributed_ellipse_coordinates(number_of_coordinates: int = 50) List[Tuple[float, float]][source]#

Returns evenly distributed coordinates along the ellipse.

Makes use of scipy.special.ellipeinc() which provides the numerical integral along the perimeter of the ellipse, and scipy.optimize.root() for solving the equal-arcs length equation for the angles.

Parameters:

number_of_coordinates – number of evenly distributed points to generate along the ellipsis line

Returns:

list of tuple’s with coordinates along the ellipse line

normalize_wrt_roi_shape(roi_shape: Rectangle) Ellipse[source]#

Transforms from the roi coordinate system to the normalized coordinate system.

This function is the inverse of denormalize_wrt_roi_shape.

Example

Assume we have Ellipse c1 which lives in the top-right quarter of a 2D space. The 2D space where c1 lives in is an roi living in the top-left quarter of the normalized coordinate space. This function returns Ellipse c1 expressed in the normalized coordinate space.

>>> from otx.api.entities.annotation import Annotation
>>> from otx.api.entities.shapes.rectangle import Rectangle
>>> from otx.api.entities.shapes.ellipse import Ellipse
>>> c1 = Ellipse(x1=0.5, y1=0.5, x2=0.6, y2=0.6)
>>> roi = Rectangle(x1=0.0, x2=0.5, y1=0.0, y2=0.5)
>>> normalized = c1.normalize_wrt_roi_shape(roi_shape)
>>> normalized
Ellipse(, x1=0.25, y1=0.25, x2=0.3, y2=0.3)
Parameters:

roi_shape – Region of Interest

Returns:

New polygon in the image coordinate system

property height: float#

Returns the height [y-axis] of the ellipse.

Example:

>>> e1 = Ellipse(x1=0.5, x2=1.0, y1=0.0, y2=0.5)
>>> e1.height
0.5
Returns:

the height of the ellipse. (y-axis)

property major_axis: float#

Returns the major axis of the ellipse.

Example:

>>> e1 = Ellipse(x1=0.5, x2=1.0, y1=0.0, y2=0.4)
>>> e1.major_axis
0.25
Returns:

major axis of ellipse.

property minor_axis: float#

Returns the minor axis of the ellipse.

Example:

>>> e1 = Ellipse(x1=0.5, x2=1.0, y1=0.0, y2=0.4)
>>> e1.minor_axis
0.2
Returns:

minor axis of ellipse.

property width: float#

Returns the width [x-axis] of the ellipse.

Example:

>>> e1 = Ellipse(x1=0.5, x2=1.0, y1=0.0, y2=0.5)
>>> e1.width
0.5
Returns:

the width of the ellipse. (x-axis)

property x_center: float#

Returns the x coordinate in the center of the ellipse.

property y_center: float#

Returns the y coordinate in the center of the ellipse.