Ellipse¶
Overview¶
Fit ellipses to root point distributions for compact spatial representation.
Key functions:
- fit_ellipse - Fit ellipse to root points
- get_ellipse_a - Get ellipse major axis
- get_ellipse_b - Get ellipse minor axis
- get_ellipse_ratio - Get ellipse aspect ratio
Quick Example¶
import sleap_roots as sr
import numpy as np
series = sr.Series.load("plant", primary_path="primary.slp")
pts = series.get_primary_points()
# Flatten to 2D points
pts_2d = pts[0, 0] # (nodes, 2)
# Fit ellipse
ellipse = sr.ellipse.fit_ellipse(pts_2d)
a = sr.ellipse.get_ellipse_a(ellipse)
b = sr.ellipse.get_ellipse_b(ellipse)
ratio = sr.ellipse.get_ellipse_ratio(ellipse)
print(f"Major axis (a): {a:.2f} px")
print(f"Minor axis (b): {b:.2f} px")
print(f"Aspect ratio: {ratio:.2f}")
API Reference¶
fit_ellipse¶
fit_ellipse ¶
Find a best fit ellipse for the points per frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pts
|
ndarray
|
Root landmarks as array of shape (..., 2). |
required |
Returns:
| Type | Description |
|---|---|
float
|
A tuple of (a, b, ratio) containing the semi-major axis length, |
float
|
semi-minor axis length, and the ratio of the major to minor lengths. |
float
|
If the ellipse fitting fails, NaNs are returned. |
Source code in sleap_roots/ellipse.py
get_ellipse_a¶
get_ellipse_a ¶
Get semi-major axis length of the fitted ellipse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pts_all_array
|
Union[ndarray, Tuple[float, float, float]]
|
landmark points or tuple of ellipse restults. |
required |
Return
Scalar of semi-major axis length.
Source code in sleap_roots/ellipse.py
get_ellipse_b¶
get_ellipse_b ¶
Get semi-minor axis length of the fitted ellipse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pts_all_array
|
Union[ndarray, Tuple[float, float, float]]
|
landmark points or tuple of ellipse restults. |
required |
Return
Scalar of semi-minor axis length.
Source code in sleap_roots/ellipse.py
get_ellipse_ratio¶
get_ellipse_ratio ¶
Get ratio of the minor to major lengths of the fitted ellipse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pts_all_array
|
Union[ndarray, Tuple[float, float, float]]
|
landmark points or tuple of ellipse restults. |
required |
Return
Scalar of ratio of the minor to major lengths.
Source code in sleap_roots/ellipse.py
Related Modules¶
- Convex Hull - Alternative spatial analysis