Convex Hull¶
Overview¶
Compute convex hull features for spatial root system analysis. Useful for measuring root system spread and spatial distribution.
Key functions:
- get_convhull - Compute convex hull polygon
- get_chull_area - Hull area
- get_chull_perimeter - Hull perimeter
Quick Example¶
import sleap_roots as sr
series = sr.Series.load("plant", primary_path="primary.slp", lateral_path="lateral.slp")
primary_pts = series.get_primary_points()
lateral_pts_list = series.get_lateral_points()
# Get all points
from sleap_roots import join_pts
all_pts = join_pts([primary_pts] + lateral_pts_list)
# Compute convex hull
hull = sr.convhull.get_convhull(all_pts)
# Compute hull traits
area = sr.convhull.get_chull_area(all_pts)
perimeter = sr.convhull.get_chull_perimeter(all_pts)
print(f"Hull area: {area:.2f} px²")
print(f"Hull perimeter: {perimeter:.2f} px")
API Reference¶
get_convhull¶
get_convhull ¶
Compute the convex hull for the points per frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pts
|
ndarray
|
Root landmarks as an array of shape (..., 2). |
required |
Returns:
| Type | Description |
|---|---|
Optional[ConvexHull]
|
An object representing the convex hull or None if a hull can't be formed. |
Source code in sleap_roots/convhull.py
get_chull_area¶
get_chull_area ¶
Calculate the area of the convex hull formed by the given points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hull
|
Union[ndarray, ConvexHull]
|
Either an array of landmark points or a pre-computed convex hull. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Scalar value representing the area of the convex hull. Returns NaN if unable |
float
|
to compute the convex hull. |
Source code in sleap_roots/convhull.py
get_chull_perimeter¶
get_chull_perimeter ¶
Calculate the perimeter of the convex hull formed by the given points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hull
|
Union[ndarray, ConvexHull, None]
|
Either an array of landmark points, a pre-computed convex hull, or None. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Scalar value representing the perimeter of the convex hull. Returns NaN if |
float
|
unable to compute the convex hull or if the input is None. |
Source code in sleap_roots/convhull.py
Related Modules¶
- Network Length - Network-level spatial metrics
- Ellipse - Alternative spatial representation