ellipse_axes
ellipse_axes(mask, spacing=None)The semi-axes of the ellipse a region implies, major first.
For a uniform filled ellipse the covariance of the member coordinates has eigenvalues a^2 / 4 and b^2 / 4, so the axes come out of an eigendecomposition of a 2x2 matrix and nothing is fitted iteratively.
It measures the region it is given and repairs nothing, which matters for a prediction: pass it through largest_filled_object first, or use ellipse_circumference, which does.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| mask | np.ndarray | One image; read as a boolean through > 0. |
required |
| spacing | Any | Pixel size in millimetres, two numbers in the array’s own axis order - (row, column). Unset returns pixels. |
None |
Returns
| Name | Type | Description |
|---|---|---|
| float | (major, minor) semi-axes, in millimetres when spacing was given and in pixels |
|
| float | otherwise. (0.0, 0.0) for fewer than three foreground pixels, which has no |
|
| tuple[float, float] | second moment. |
Raises
| Name | Type | Description |
|---|---|---|
| MeasureError | If mask is not one image, or spacing is not two positive numbers. |
mask = np.zeros((41, 41), dtype=bool) rows, columns = np.ogrid[:41, :41] mask[((rows - 20) / 10) ** 2 + ((columns - 20) / 20) ** 2 <= 1] = True tuple(round(axis) for axis in ellipse_axes(mask)) (20, 10)