eyepy.quant
Quantification module for ophthalmic image analysis.
This module provides tools for quantifying features in ophthalmic images, including area measurements and spatial extent calculations relative to anatomical landmarks.
AnatomicalOrigin(y, x, laterality, mode)
dataclass
Reference origin based on anatomical landmarks.
Defines a coordinate system origin that can be based on the optic disc, fovea, a hybrid approach, or a custom position.
Coordinate System Convention: This class uses (row, col) image coordinates for input and output: - row: vertical axis, increases downward (corresponds to y) - col: horizontal axis, increases rightward (corresponds to x)
The internal storage uses (y, x) where y=row and x=col. All methods that accept or return coordinates use (row, col) format unless explicitly documented otherwise.
Attributes:
| Name | Type | Description |
|---|---|---|
y |
float
|
Vertical (y) coordinate of the origin |
x |
float
|
Horizontal (x) coordinate of the origin |
laterality |
str
|
Eye laterality ('OD' or 'OS') |
mode |
OriginMode
|
Origin mode used to determine the position |
from_custom(origin, laterality)
classmethod
Create origin at custom position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
origin
|
tuple[float, float]
|
(y, x) coordinates of custom origin |
required |
laterality
|
str
|
Eye laterality ('OD' or 'OS') |
required |
Returns:
| Type | Description |
|---|---|
AnatomicalOrigin
|
AnatomicalOrigin at custom position |
Source code in src/eyepy/quant/spatial.py
from_fovea(fovea_center, laterality)
classmethod
Create origin at fovea center.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fovea_center
|
tuple[float, float]
|
(y, x) coordinates of fovea center |
required |
laterality
|
str
|
Eye laterality ('OD' or 'OS') |
required |
Returns:
| Type | Description |
|---|---|
AnatomicalOrigin
|
AnatomicalOrigin at fovea center |
Source code in src/eyepy/quant/spatial.py
from_hybrid(optic_disc_center, fovea_center, laterality)
classmethod
Create hybrid origin from optic disc and fovea positions.
Uses the horizontal (x) position from the optic disc center and the vertical (y) position from the fovea center.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
optic_disc_center
|
tuple[float, float]
|
(y, x) coordinates of optic disc center |
required |
fovea_center
|
tuple[float, float]
|
(y, x) coordinates of fovea center |
required |
laterality
|
str
|
Eye laterality ('OD' or 'OS') |
required |
Returns:
| Type | Description |
|---|---|
AnatomicalOrigin
|
AnatomicalOrigin with y from fovea, x from optic disc |
Source code in src/eyepy/quant/spatial.py
from_optic_disc(optic_disc_center, laterality)
classmethod
Create origin at optic disc center.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
optic_disc_center
|
tuple[float, float]
|
(y, x) coordinates of optic disc center |
required |
laterality
|
str
|
Eye laterality ('OD' or 'OS') |
required |
Returns:
| Type | Description |
|---|---|
AnatomicalOrigin
|
AnatomicalOrigin at optic disc center |
Source code in src/eyepy/quant/spatial.py
to_cartesian(y, x)
Convert image coordinates (row, col) to Cartesian coordinates relative to origin.
Image coordinates use (row, col) convention where: - row increases downward - col increases to the right
Cartesian output coordinates are anatomically oriented: - x: horizontal (positive = temporal, negative = nasal) - y: vertical (positive = inferior, negative = superior)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
float
|
Image row coordinate (increases downward) |
required |
x
|
float
|
Image column coordinate (increases to the right) |
required |
Returns:
| Type | Description |
|---|---|
float
|
(x_cart, y_cart) Cartesian coordinates relative to origin where: |
float
|
|
tuple[float, float]
|
|
Source code in src/eyepy/quant/spatial.py
to_polar(y, x)
Convert image coordinates (row, col) to polar coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
float
|
Image row coordinate (increases downward) |
required |
x
|
float
|
Image column coordinate (increases to the right) |
required |
Returns:
| Type | Description |
|---|---|
float
|
(distance, angle) where: |
float
|
|
tuple[float, float]
|
|
Source code in src/eyepy/quant/spatial.py
DirectionalExtent(temporal, nasal, superior, inferior, superior_temporal, inferior_temporal, superior_nasal, inferior_nasal)
dataclass
Extent of a region in specific directions from origin.
Contains ExtentMetrics for each of the 8 anatomical directions (4 cardinal + 4 ordinal) from an anatomical origin. Each direction includes mean, max, median, and standard deviation of boundary distances, along with a flag indicating if that specific direction touches the image border.
Attributes:
| Name | Type | Description |
|---|---|---|
temporal |
ExtentMetrics
|
Extent metrics in temporal direction |
nasal |
ExtentMetrics
|
Extent metrics in nasal direction |
superior |
ExtentMetrics
|
Extent metrics in superior direction |
inferior |
ExtentMetrics
|
Extent metrics in inferior direction |
superior_temporal |
ExtentMetrics
|
Extent metrics in superior-temporal direction |
inferior_temporal |
ExtentMetrics
|
Extent metrics in inferior-temporal direction |
superior_nasal |
ExtentMetrics
|
Extent metrics in superior-nasal direction |
inferior_nasal |
ExtentMetrics
|
Extent metrics in inferior-nasal direction |
to_dict()
Convert to dictionary.
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with nested structure: direction -> metric -> value |
Source code in src/eyepy/quant/spatial.py
ExtentMetrics(midpoint, mean, max, median, std, touches_border=False)
dataclass
Metrics for extent in a single direction.
Contains statistical measures of distances from the origin to boundary points within a single angular sector.
Attributes:
| Name | Type | Description |
|---|---|---|
midpoint |
float
|
Distance to boundary at exact midpoint angle of this direction |
mean |
float
|
Mean distance to boundary points in this direction |
max |
float
|
Maximum distance to boundary in this direction |
median |
float
|
Median distance to boundary points in this direction |
std |
float
|
Standard deviation of distances in this direction |
touches_border |
bool
|
Whether the region extends to the image border in this specific direction, indicating measurements may be truncated |
to_dict()
Convert to dictionary.
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary mapping metric names to values |
Source code in src/eyepy/quant/spatial.py
OriginMode
Bases: Enum
Mode for determining the anatomical origin.
OPTIC_DISC: Use optic disc center as origin FOVEA: Use fovea center as origin HYBRID: Use optic disc x-coordinate and fovea y-coordinate CUSTOM: Use a custom user-specified origin point
PolarReference(origin)
Polar coordinate reference system for spatial analysis.
Divides the image into 8 angular sectors (4 cardinal + 4 ordinal directions) relative to an anatomical origin for computing directional statistics.
Attributes:
| Name | Type | Description |
|---|---|---|
origin |
Anatomical origin point |
Initialize polar reference system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
origin
|
AnatomicalOrigin
|
Anatomical origin defining the coordinate system |
required |
Source code in src/eyepy/quant/spatial.py
compute_directional_extent(mask, scale_x=1.0, scale_y=1.0)
Compute extent in all 8 directions with complete metrics.
For each of the 8 anatomical directions (4 cardinal + 4 ordinal), computes: - Midpoint distance: distance to boundary at exact direction angle - Mean, max, median, std: statistics of all boundary points in that sector - Border flag: whether that specific direction touches the image border
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
NDArray[bool_]
|
Binary mask of the region |
required |
scale_x
|
float
|
Micrometers per pixel in x-direction |
1.0
|
scale_y
|
float
|
Micrometers per pixel in y-direction |
1.0
|
Returns:
| Type | Description |
|---|---|
DirectionalExtent
|
DirectionalExtent with ExtentMetrics for all 8 directions |
Source code in src/eyepy/quant/spatial.py
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | |
compute_area(mask, scale_x=1.0, scale_y=1.0)
Compute area of a binary mask in physical units.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
NDArray[bool_]
|
Binary mask (True = region of interest) |
required |
scale_x
|
float
|
Micrometers per pixel in x-direction (default: 1.0) |
1.0
|
scale_y
|
float
|
Micrometers per pixel in y-direction (default: 1.0) |
1.0
|
Returns:
| Type | Description |
|---|---|
float
|
Area in square micrometers (or square pixels if scales are 1.0) |