phenotypic.grid.ManualGridFinder#

class phenotypic.grid.ManualGridFinder(row_edges: numpy.ndarray, col_edges: numpy.ndarray)[source]

Bases: GridFinder

A GridFinder implementation where users directly specify grid row and column coordinates.

This class allows for complete manual control over grid placement by accepting explicit row and column edge coordinates. No optimization or automatic calculation is performed - the grid is defined exactly as specified by the user.

Parameters:
  • row_edges (np.ndarray)

  • col_edges (np.ndarray)

nrows

Number of rows in the grid (derived from row_edges).

Type:

int

ncols

Number of columns in the grid (derived from col_edges).

Type:

int

row_edges

Array of row edge coordinates defining grid rows.

Type:

np.ndarray

col_edges

Array of column edge coordinates defining grid columns.

Type:

np.ndarray

Example

Create a 3x4 grid with specific coordinates:

>>> import numpy as np
>>> from phenotypic.grid import ManualGridFinder
>>> # Create a 3x4 grid with specific coordinates
>>> row_edges = np.array([0, 100, 200, 300])  # 3 rows
>>> col_edges = np.array([0, 80, 160, 240, 320])  # 4 columns
>>> finder = ManualGridFinder(row_edges=row_edges, col_edges=col_edges)
>>> grid_info = finder.measure(image)  

Methods

__init__

Initialize a ManualGridFinder with explicit row and column edge coordinates.

get_col_edges

Returns the manually specified column edges.

get_row_edges

Returns the manually specified row edges.

measure

Compute grid edges and assign each detected object to a grid cell.

__init__(row_edges: numpy.ndarray, col_edges: numpy.ndarray)[source]

Initialize a ManualGridFinder with explicit row and column edge coordinates.

Parameters:
  • row_edges (np.ndarray) – Array of row edge coordinates. Length should be nrows + 1. Example: [0, 100, 200, 300] defines 3 rows.

  • col_edges (np.ndarray) – Array of column edge coordinates. Length should be ncols + 1. Example: [0, 80, 160, 240, 320] defines 4 columns.

Raises:

ValueError – If row_edges or col_edges have fewer than 2 elements.

get_row_edges(image: Image) np.ndarray[source]

Returns the manually specified row edges.

Parameters:

image (Image) – The image (not used, but required by interface).

Returns:

Array of row edge coordinates.

Return type:

np.ndarray

get_col_edges(image: Image) np.ndarray[source]

Returns the manually specified column edges.

Parameters:

image (Image) – The image (not used, but required by interface).

Returns:

Array of column edge coordinates.

Return type:

np.ndarray

__del__()

Automatically stop tracemalloc when the object is deleted.

measure(image)

Compute grid edges and assign each detected object to a grid cell.

Parameters:

image – Image with detected objects.

Returns:

DataFrame with grid assignments (ROW_NUM, COL_NUM, ROW_MAJOR_IDX).