phenotypic.grid.AutoGridFinder#

class phenotypic.grid.AutoGridFinder(nrows: int = 8, ncols: int = 12, tol: float = 0.01, max_iter: int | None = None)[source]#

Bases: GridFinder

Automatically adjusts and processes grid configurations for images based on parameters like row and column counts, tolerance, and iteration constraints.

This class extends GridFinder and adds flexibility to define custom grid specifications, compute padding, manage convergence criteria, and optimize grid alignment for image processing tasks.

Attributes:

__iter_limit (float): Internal limit for the maximum number of iterations. nrows (int): Number of rows for the grid structure. ncols (int): Number of columns for the grid structure. tol (float): Tolerance level to assess convergence. max_iter (int): Maximum allowable iterations, capped by the internal limit.

Category: GRID#

Name

Description

RowNum

The row idx of the object

RowIntervalStart

The start of the row interval of the object

RowIntervalEnd

The end of the row interval of the object

ColNum

The column idx of the object

ColIntervalStart

The start of the column interval of the object

ColIntervalEnd

The end of the column interval of the object

SectionNum

The section number of the object. Ordered left to right, top to bottom

Methods

__init__

Represents a configuration object for iterative computations with constraints on the number of nrows, columns, tolerance, and a maximum number of iterations.

get_col_edges

This method is to returns the column edges of the grid as numpy rgb.

get_row_edges

Extracts and returns the edges of nrows from the given image.

measure

Processes an arr image to calculate and organize grid-based boundaries and centroids using coordinates.

Parameters:
__init__(nrows: int = 8, ncols: int = 12, tol: float = 0.01, max_iter: int | None = None)[source]#

Represents a configuration object for iterative computations with constraints on the number of nrows, columns, tolerance, and a maximum number of iterations. This provides a flexible structure enabling adjustments to the computation parameters such as matrix dimensions and convergence criteria.

Parameters:
nrows#

Number of nrows for the computation grid or array.

Type:

int

ncols#

Number of columns for the computation grid or array.

Type:

int

tol#

Tolerance level for the convergence criteria.

Type:

float

max_iter#

Maximum number of allowable iterations. Defaults to the predefined internal convergence limit if not provided.

Type:

int | None

get_row_edges(image: Image)[source]#

Extracts and returns the edges of nrows from the given image.

This method first calculates the optimal row padding for the provided image using an internal utility method and subsequently determines the row edges based on the calculated padding and metadata of the image.

Parameters:

image (Image) – The input image from which the row edges need to be identified.

Returns:

A list representing the edges of the nrows in the image.

Return type:

list

get_col_edges(image: Image)[source]#

This method is to returns the column edges of the grid as numpy rgb. :param image:

Returns:

Column-edges of the grid.

Return type:

np.ndarray

Parameters:

image (Image)

__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