histocartography.preprocessing.nuclei_extraction module

Detect and Classify nuclei from an image with the HoverNet model.

Summary

Classes:

ImageToPatchDataset

Helper class to transform an image as a set of patched wrapped in a pytorch dataset

NucleiExtractor

Nuclei extraction

Functions:

process_instance

Post processing script for image tiles

process_np_hv_channels

Process Nuclei Prediction with XY Coordinate Map

class NucleiExtractor(pretrained_data: str = 'pannuke', model_path: Optional[str] = None, batch_size: Optional[int] = None, **kwargs)[source]

Bases: histocartography.pipeline.PipelineStep

Nuclei extraction

__init__(pretrained_data: str = 'pannuke', model_path: Optional[str] = None, batch_size: Optional[int] = None, **kwargs)None[source]

Create a nuclei extractor

Parameters
  • pretrained_data (str) – Load checkpoint pretrained on some data. Options are ‘pannuke’ or ‘monusac’. Default to ‘pannuke’.

  • model_path (str) – Path to a pre-trained model. If none, the checkpoint specified in pretrained_data will be used. Default to None.

  • batch_size (int, optional) – Batch size. Defaults to None.

precompute(link_path: Union[None, str, pathlib.Path] = None, precompute_path: Union[None, str, pathlib.Path] = None)None[source]

Precompute all necessary information

Parameters
  • link_path (Union[None, str, Path], optional) – Path to link to. Defaults to None.

  • precompute_path (Union[None, str, Path], optional) – Path to save precomputation outputs. Defaults to None.

class ImageToPatchDataset(image: numpy.ndarray)[source]

Bases: torch.utils.data.dataset.Dataset

Helper class to transform an image as a set of patched wrapped in a pytorch dataset

__init__(image: numpy.ndarray)None[source]
Create a dataset for a given image and extracted instance maps with desired patches.

Patches have shape of (3, 256, 256) as defined by HoverNet model.

Parameters

image (np.ndarray) – RGB input image

process_np_hv_channels(pred: numpy.ndarray)numpy.ndarray[source]

Process Nuclei Prediction with XY Coordinate Map

Parameters

pred (np.ndarray) – HoverNet model output, that contains: - channel 0 contain probability map of nuclei - channel 1 contains X-map - channel 2 contains Y-map

Returns

instance map

Return type

pred_instance (np.ndarray)

process_instance(pred_map: numpy.ndarray, output_dtype: str = 'uint16')numpy.ndarray[source]

Post processing script for image tiles

Parameters
  • pred_map (np.ndarray) – commbined output of np and hv branches

  • output_dtype (str) – data type of output

Returns

pixel-wise nuclear instance segmentation prediction

Return type

pred_inst (np.ndarray)

Reference

If you use histocartography in your projects, please cite the following:

@inproceedings{pati2021,
    title = {Hierarchical Graph Representations for Digital Pathology},
    author = {Pushpak Pati, Guillaume Jaume, Antonio Foncubierta, Florinda Feroce, Anna Maria Anniciello, Giosuè Scognamiglio, Nadia Brancati, Maryse Fiche, Estelle Dubruc, Daniel Riccio, Maurizio Di Bonito, Giuseppe De Pietro, Gerardo Botti, Jean-Philippe Thiran, Maria Frucci, Orcun Goksel, Maria Gabrani},
    booktitle = {https://arxiv.org/pdf/2102.11057},
    year = {2021}
}