cellmil.segmentation.cell_segmenter¶
Functions
|
Get cell position as a list |
|
Get the status of the cell, describing the cell position |
|
Classes
|
|
|
Class for cell instance segmentation in whole slide images. |
- class cellmil.segmentation.cell_segmenter.CellSegmenter(config: CellSegmenterConfig)[source]¶
Bases:
objectClass for cell instance segmentation in whole slide images.
Features reliable multiprocessing with Pool.imap and automatic fallback to sequential processing if multiprocessing fails.
- __init__(config: CellSegmenterConfig) None[source]¶
- set_wsi(wsi_path: str | pathlib.Path, patched_slide_path: str | pathlib.Path) None[source]¶
Set the WSI path and patched slide path for segmentation.
- _get_wsi_dimensions() tuple[int, int][source]¶
Get the dimensions (width, height) of the WSI at level 0.
- _are_contour_coordinates_valid(contour_global: ndarray[Any, Any]) bool[source]¶
Check if contour coordinates are within the WSI bounds.
- Parameters:
contour_global (np.ndarray) – Global contour coordinates, shape (N, 2) where each point is [x, y]
- Returns:
True if all contour points are within WSI bounds, False otherwise
- Return type:
- get_cell_predictions(predictions: dict[str, torch.Tensor], magnification: float | int = 40) list[dict[numpy.int32, dict[str, Any]]] | list[dict[int, dict[str, Any]]][source]¶
Get cell predictions from model output
- Parameters:
predictions (torch.Tensor) – Model output
magnification (float, optional) – Magnification of the WSI. Defaults to 40.0.
- Returns:
Dictionary with cell predictions
- Return type:
- cellmil.segmentation.cell_segmenter.get_cell_position(bbox: ndarray[Any, Any], patch_size: int = 1024) list[int][source]¶
Get cell position as a list
Entry is 1, if cell touches the border: [top, right, down, left]
- cellmil.segmentation.cell_segmenter.get_cell_position_marging(bbox: ndarray[Any, Any], patch_size: int = 1024, margin: int = 64) Literal[0, 1, 2, 3, 4, 5, 6, 7, 8][source]¶
Get the status of the cell, describing the cell position
A cell is either in the mid (0) or at one of the borders (1-8)
# Numbers are assigned clockwise, starting from top left # i.e., top left = 1, top = 2, top right = 3, right = 4, bottom right = 5 bottom = 6, bottom left = 7, left = 8 # Mid status is denoted by 0
- cellmil.segmentation.cell_segmenter.get_edge_patch(position: list[int], row: int, col: int)[source]¶
- class cellmil.segmentation.cell_segmenter.CellPostProcessor(cell_list: list[dict[str, Any]], logger: Logger)[source]¶
Bases:
object- __init__(cell_list: list[dict[str, Any]], logger: Logger) None[source]¶
Post-Processing a list of cells from one WSI
- Parameters:
cell_list (List[dict]) – List with cell-dictionaries. Required keys: * bbox * centroid * contour * type_prob * type * patch_coordinates * cell_status * offset_global
logger (logging.Logger) – Logger
- post_process_cells() DataFrame[source]¶
Main Post-Processing coordinator, entry point
- Returns:
DataFrame with post-processed and cleaned cells
- Return type:
pd.DataFrame
- _clean_edge_cells() DataFrame[source]¶
Create a DataFrame that just contains all margin cells (cells inside the margin, not touching the border) and border/edge cells (touching border) with no overlapping equivalent (e.g, if patch has no neighbour)
- Returns:
Cleaned DataFrame
- Return type:
pd.DataFrame