cellmil.data.storage¶
Classes
|
Storage class to store all WSI related files |
- class cellmil.data.storage.Storage(wsi_name: str, output_path: Union[Path, str], metadata: dict[str, Any], mask_images: dict[str, PIL.Image.Image], mask_images_annotations: dict[str, PIL.Image.Image], thumbnails: dict[str, PIL.Image.Image], store_masks: bool = False, save_context: bool = False, context_scales: Optional[List[int]] = None)[source]¶
Bases:
objectStorage class to store all WSI related files
Generates the following folder structure for storage:
- Output-Path/WSI-Name
metadata.yaml: Metadata of the WSI
annotation_masks: preview images of annotations
patches: store extracted patches with each path “wsi_name_row_col.png”
metadata: store metadata for each path “wsi_name_row_col.yaml”
thumbnails: WSI thumbnails
tissue masks: Masks of tissue detection
Optional: context: context folder with subfolder for each context scale
Optional: masks: Masks for each patch as .npy files (numpy arrays)
- Parameters:
wsi_name (str) – Name of the WSI, as string. Just the name without suffix and no path!
output_path (Union[Path, str]) – Path to the folder where the resulting dataset should be stored.
metadata (dict) – Metadata of the WSI. Is stored in parent directory
mask_images (dict[str, Image]) – Masks generated during tissue detection stored in dict with keys equals the mask name and values equals the PIL image
mask_images_annotations (dict[str, Image]) – Annotation masks for provided annotations for the complete WSI. Masks are equal to the tissue masks sizes. Keys are the mask names and values are the PIL images.
thumbnails (dict[str, Image]) – Dictionary with thumbnails and corresponding thumbnail names. Names are keys, PIL Images are values
store_masks (bool, optional) – Set to store masks per patch. Defaults to False.
save_context (bool, optional) – If context patches are provided. Defaults to False.
context_scales (List[int], optional) – List with context scales. Defaults to None.
- __init__(wsi_name: str, output_path: Union[Path, str], metadata: dict[str, Any], mask_images: dict[str, PIL.Image.Image], mask_images_annotations: dict[str, PIL.Image.Image], thumbnails: dict[str, PIL.Image.Image], store_masks: bool = False, save_context: bool = False, context_scales: Optional[List[int]] = None) None[source]¶
- save_elem_to_disk(patch_result: tuple[numpy.ndarray[Any, Any], dict[str, Any], None, dict[str, Any]]) None[source]¶
- clean_up(patch_distribution: dict[int, int], patch_metadata_list: list[dict[str, dict[str, Any]]])[source]¶
Clean-Up function, called after WSI has been processed. Appends WSI to processed.json file and generated a metadata file in root folder called patch_metadata.json with merged metadata for all patches in one file.