cellmil.datamodels¶
- class cellmil.datamodels.WSI(name: str, patient: str, slide_path: Union[str, Path], patched_slide_path: Optional[Path] = None, embedding_name: Optional[Union[str, Path]] = None, label: Optional[Union[str, int, float, ndarray[Any, Any]]] = None, logger: Optional[Logger] = None)[source]¶
Bases:
objectWSI object
- Parameters:
name (str) – WSI name
patient (str) – Patient name
slide_path (Union[str, Path]) – Full path to the WSI file.
patched_slide_path (Union[str, Path], optional) – Full path to preprocessed WSI files (patches). Defaults to None.
embedding_name (Union[str, Path], optional) – Defaults to None.
label (Union[str, int, float, np.ndarray], optional) – Label of the WSI. Defaults to None.
logger (logging.logger, optional) – Logger module for logging information. Defaults to None.
- load_patch_metadata(patch_name: str) dict[str, Any][source]¶
Return the metadata of a patch with given name (including patch suffix, e.g., wsi_1_1.png)
This function assumes that metadata path is a subpath of the patches dataset path
- set_patch_transform(transform: Callable[[Any], Any]) None[source]¶
Set the transformation function to process a patch
- Parameters:
transform (Callable) – Transformation function
- process_patch_image(patch_name: str, transform: Optional[Compose] = None) Tuple[Tensor, dict[str, Any]][source]¶
Process one patch: Load from disk, apply transformation if needed. ToTensor is applied automatically
- Parameters:
patch_name (Path) – Name of patch to load, including patch suffix, e.g., wsi_1_1.png
transform (Callable, optional) – Optional Patch-Transformation
- Returns:
torch.Tensor: patch as torch.tensor (:,:,3)
dict: patch metadata as dictionary
- Return type:
Tuple[torch.Tensor, dict]
- get_number_patches() int[source]¶
Return the number of patches for this WSI
- Returns:
number of patches
- Return type:
- get_patches(transform: Callable[[Any], Any]) Tuple[Tensor, list[dict[str, Any]]][source]¶
Get all patches for one image
- Parameters:
transform (Callable, optional) – Optional Patch-Transformation
- Returns:
patched image: Shape of torch.Tensor(num_patches, 3, :, :)
coordinates as list metadata_dictionary
- Return type:
Tuple[torch.Tensor, list]
- load_embedding() Tensor[source]¶
Load embedding from subfolder patched_slide_path/embedding/
- Raises:
FileNotFoundError – If embedding is not given
- Returns:
WSI embedding
- Return type:
Modules
Feature and label transforms for preprocessing. |
|