Graph API

Graph Building

class pathml.graph.preprocessing.BaseGraphBuilder(nr_annotation_classes: int = 5, annotation_background_class=None, add_loc_feats=False, return_networkx=False, **kwargs)

Base interface class for graph building.

Parameters:
  • nr_annotation_classes (int) – Number of classes in annotation. Used only if setting node labels.

  • annotation_background_class (int) – Background class label in annotation. Used only if setting node labels.

  • add_loc_feats (bool) – Flag to include location-based features (ie normalized centroids) in node feature representation. Defaults to False.

  • return_networkx (bool) – Whether to return as a networkx graph object. Deafults to returning a Pytorvh Geometric Data object.

References

[1] https://github.com/BiomedSciAI/histocartography/tree/main with an AGPL-3.0 license (https://www.gnu.org/licenses/) [2] Jaume, G., Pati, P., Anklin, V., Foncubierta, A. and Gabrani, M., 2021, September. Histocartography: A toolkit for graph analytics in digital pathology. In MICCAI Workshop on Computational Pathology (pp. 117-128). PMLR.

process(instance_map, features=None, annotation=None, target=None)

Generates a graph from a given instance_map and features

process_with_centroids(centroids, features=None, image_size=None, annotation=None, target=None)

Generates a graph from a given node centroids and features

class pathml.graph.preprocessing.KNNGraphBuilder(k=5, thresh=None, **kwargs)

k-Nearest Neighbors Graph class for graph building.

Parameters:
  • k (int, optional) – Number of neighbors. Defaults to 5.

  • thresh (int, optional) – Maximum allowed distance between 2 nodes. Defaults to None (no thresholding).

Returns:

A pathml.graph.utils.Graph object containing node and edge information.

References

[1] https://github.com/BiomedSciAI/histocartography/tree/main with an AGPL-3.0 license (https://www.gnu.org/licenses/) [2] Jaume, G., Pati, P., Anklin, V., Foncubierta, A. and Gabrani, M., 2021, September. Histocartography: A toolkit for graph analytics in digital pathology. In MICCAI Workshop on Computational Pathology (pp. 117-128). PMLR.

class pathml.graph.preprocessing.RAGGraphBuilder(kernel_size=3, hops=1, **kwargs)

Region Adjacency Graph builder class.

Parameters:
  • kernel_size (int, optional) – Size of the kernel to detect connectivity. Defaults to 5.

  • hops (int, optional) – Number of hops in a multi-hop neighbourhood. Defaults to 1.

Returns:

A pathml.graph.utils.Graph object containing node and edge information.

References

[1] https://github.com/BiomedSciAI/histocartography/tree/main with an AGPL-3.0 license (https://www.gnu.org/licenses/) [2] Jaume, G., Pati, P., Anklin, V., Foncubierta, A. and Gabrani, M., 2021, September. Histocartography: A toolkit for graph analytics in digital pathology. In MICCAI Workshop on Computational Pathology (pp. 117-128). PMLR.

class pathml.graph.preprocessing.MSTGraphBuilder(k=5, thresh=None, **kwargs)

Minimum Spanning Tree Graph class for graph building.

Parameters:
  • k (int, optional) – Number of neighbors. Defaults to 5.

  • thresh (int, optional) – Maximum allowed distance between 2 nodes. Defaults to None (no thresholding).

Returns:

A pathml.graph.utils.Graph object containing node and edge information.

Tissue Extraction

class pathml.graph.preprocessing.SuperpixelExtractor(nr_superpixels: int = None, superpixel_size: int = None, max_nr_superpixels=None, blur_kernel_size=1, compactness=20, max_iterations=10, threshold=0.03, connectivity=2, color_space='rgb', downsampling_factor=1, **kwargs)

Helper class to extract superpixels from images

Parameters:
  • nr_superpixels (None, int) – The number of super pixels before any merging.

  • superpixel_size (None, int) – The size of super pixels before any merging.

  • max_nr_superpixels (int, optional) – Upper bound for the number of super pixels. Useful when providing a superpixel size.

  • blur_kernel_size (float, optional) – Size of the blur kernel. Defaults to 0.

  • compactness (int, optional) – Compactness of the superpixels. Defaults to 30.

  • max_iterations (int, optional) – Number of iterations of the slic algorithm. Defaults to 10.

  • threshold (float, optional) – Connectivity threshold. Defaults to 0.03.

  • connectivity (int, optional) – Connectivity for merging graph. Defaults to 2.

  • downsampling_factor (int, optional) – Downsampling factor from the input image resolution. Defaults to 1.

References

[1] https://github.com/BiomedSciAI/histocartography/tree/main with an AGPL-3.0 license (https://www.gnu.org/licenses/) [2] Jaume, G., Pati, P., Anklin, V., Foncubierta, A. and Gabrani, M., 2021, September. Histocartography: A toolkit for graph analytics in digital pathology. In MICCAI Workshop on Computational Pathology (pp. 117-128). PMLR.

process(input_image, tissue_mask=None)

Return the superpixels of a given input image

class pathml.graph.preprocessing.SLICSuperpixelExtractor(**kwargs)

Use the SLIC algorithm to extract superpixels.

References

[1] https://github.com/BiomedSciAI/histocartography/tree/main with an AGPL-3.0 license (https://www.gnu.org/licenses/) [2] Jaume, G., Pati, P., Anklin, V., Foncubierta, A. and Gabrani, M., 2021, September. Histocartography: A toolkit for graph analytics in digital pathology. In MICCAI Workshop on Computational Pathology (pp. 117-128). PMLR.

class pathml.graph.preprocessing.MergedSuperpixelExtractor(**kwargs)

Use the SLIC algorithm to extract superpixels and a merging function to merge superpixels

References

[1] https://github.com/BiomedSciAI/histocartography/tree/main with an AGPL-3.0 license (https://www.gnu.org/licenses/) [2] Jaume, G., Pati, P., Anklin, V., Foncubierta, A. and Gabrani, M., 2021, September. Histocartography: A toolkit for graph analytics in digital pathology. In MICCAI Workshop on Computational Pathology (pp. 117-128). PMLR.

process(input_image, tissue_mask=None)

Return the superpixels of a given input image

class pathml.graph.preprocessing.ColorMergedSuperpixelExtractor(w_hist: float = 0.5, w_mean: float = 0.5, **kwargs)

Superpixel merger based on color attibutes taken from the HACT-Net Implementation :param w_hist: Weight of the histogram features for merging. Defaults to 0.5. :type w_hist: float, optional :param w_mean: Weight of the mean features for merging. Defaults to 0.5. :type w_mean: float, optional

References

[1] https://github.com/BiomedSciAI/histocartography/tree/main with an AGPL-3.0 license (https://www.gnu.org/licenses/) [2] Jaume, G., Pati, P., Anklin, V., Foncubierta, A. and Gabrani, M., 2021, September. Histocartography: A toolkit for graph analytics in digital pathology. In MICCAI Workshop on Computational Pathology (pp. 117-128). PMLR.

Graph Feature Extraction

class pathml.graph.preprocessing.GraphFeatureExtractor(use_weight=False, alpha=0.85)

Extracts features from a networkx graph object.

Parameters:
  • use_weight (bool, optional) – Whether to use edge weights for feature computation. Defaults to False.

  • alpha (float, optional) – Alpha value for personalized page-rank. Defaults to 0.85.

Returns:

Dictionary of keys as feature type and values as features

get_stats(dct, prefix='add_pre')
process(G)