cellmil.features

class cellmil.features.FeatureExtractor(config: FeatureExtractorConfig)[source]

Bases: object

Feature extractor for whole slide images.

__init__(config: FeatureExtractorConfig)[source]
_load_cells()[source]

Load cell data from the specified path.

_load_metadata()[source]

Load metadata from the patched slide path to get patch size and overlap.

_load_graph()[source]

Load graph from the specified path

get_features()[source]

Extract features from the whole slide image using parallel processing.

static _load_patch(patched_slide_path: Path, row: int, col: int) ndarray[Any, Any][source]

Load a patch image from the file system.

Parameters:
  • patched_slide_path (Path) – Path to the patched slide directory

  • row (int) – Row coordinate of the patch

  • col (int) – Column coordinate of the patch

Returns:

The patch image as a numpy array

Return type:

np.ndarray

Raises:

FileNotFoundError – If the patch file doesn’t exist

static _get_patch_path(patched_slide_path: Path, row: int, col: int) Path[source]

Get the path to a patch file based on row and column coordinates.

Parameters:
  • patched_slide_path (Path) – Path to the patched slide directory

  • row (int) – Row coordinate of the patch

  • col (int) – Column coordinate of the patch

Returns:

Full path to the patch file

Return type:

Path

_save_pt(results: list[dict[str, Any]])[source]

Save extracted features to a PyTorch file. (Faster than JSON)

_results_to_tensor(data: list[dict[str, Any]]) Tensor[source]

Convert a dictionary of features to a PyTorch tensor.

Parameters:

data – List of dictionaries containing cell_id and features

Returns:

Tensor of shape [N, D] where N is the number of cells

and D is the number of features

Return type:

torch.Tensor

static _get_morphological_features(item: dict[str, Any]) Optional[dict[str, Any]][source]

Process a single cell and extract features.

static create_cell_mask(cell_contour: list[list[int]], patch_bounds: tuple[int, int, int, int], patch_shape: tuple[int, int]) tuple[numpy.ndarray[Any, Any], int][source]

Create a binary mask from cell contour for a specific patch region only.

Parameters:
  • cell_contour – List of [x, y] coordinates defining the cell boundary

  • patch_bounds – Tuple of (x_min, y_min, x_max, y_max) defining the patch region

  • patch_shape – Tuple of (height, width) for the output mask

Returns:

Binary mask array with shape patch_shape

static _get_topological_features(item: dict[str, Any]) Optional[dict[str, Any]][source]

Process a single cell and extract features.

Modules