phenotypic.grid.ManualGridFinder#
- class phenotypic.grid.ManualGridFinder(row_edges: numpy.ndarray, col_edges: numpy.ndarray)[source]#
Bases:
GridFinderA 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)
- 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
>>> # 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
Initialize a ManualGridFinder with explicit row and column edge coordinates.
Returns the manually specified column edges.
Returns the manually specified row edges.
Processes an arr image to calculate and organize grid-based boundaries and centroids using coordinates.
- __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)#
Processes an arr image to calculate and organize grid-based boundaries and centroids using coordinates. This function implements a two-pass approach to refine row and column boundaries with exact precision, ensuring accurate grid labeling and indexing. The function dynamically computes boundary intervals and optimally segments the arr space into grids based on specified nrows and columns.
- Parameters:
image (Image) – The arr image to be analyzed and processed.
- Returns:
A DataFrame containing the grid results including boundary intervals, grid indices, and section numbers corresponding to the segmented arr image.
- Return type:
pd.DataFrame