slideflow.mosaic¶
This module provides the slideflow.Mosaic class, which plots tile images onto a map of slides,
generating mosaic maps.
The idea of a mosaic map is to visualize image feature variation across slides and among categories, in an attempt
to better understand the kinds of image features discriminative models might be using to generate class predictions.
They are created by first generating whole-dataset layer features (using
slideflow.model.DatasetFeatures), which are then mapped into two-dimensional space using UMAP
dimensionality reduction (slideflow.SlideMap). This resulting SlideMap is then passed to
slideflow.Mosaic, which overlays tile images onto the dimensionality-reduced slide map.
An example of a mosaic map can be found in Figure 4 of this paper. It bears some resemblence to the Activation Atlases created by Google and OpenAI, without the use of feature inversion.
Mosaic¶
- class slideflow.Mosaic(slide_map, tfrecords, leniency=1.5, expanded=False, num_tiles_x=50, tile_select='nearest', tile_meta=None, normalizer=None, normalizer_source=None)¶
Visualization of tiles mapped using dimensionality reduction.
- __init__(slide_map, tfrecords, leniency=1.5, expanded=False, num_tiles_x=50, tile_select='nearest', tile_meta=None, normalizer=None, normalizer_source=None)¶
Generate a mosaic map.
- Parameters
slide_map (
slideflow.SlideMap) – SlideMap object.leniency (float, optional) – UMAP leniency.
expanded (bool, optional) – If true, will try to fill in blank spots on the UMAP with nearby tiles. Increases generation time. Defaults to False.
num_tiles_x (int, optional) – Mosaic map grid size. Defaults to 50.
tile_select (str, optional) – Either ‘nearest’ or ‘centroid’. Determines how to choose a tile for display on each grid space. If ‘nearest’, will display tile nearest to center of grid. If ‘centroid’, for each grid, will calculate which tile is nearest to centroid tile_meta. Defaults to ‘nearest’.
tile_meta (dict, optional) – Tile metadata, used for tile_select. Dictionary should have slide names as keys, mapped to list of metadata (length of list = number of tiles in slide). Defaults to None.
normalizer ((str or slideflow.norm.StainNormalizer), optional) – Normalization strategy to use on image tiles. Defaults to None.
normalizer_source (str, optional) – Path to normalizer source image. If None, normalizer will use slideflow.slide.norm_tile.jpg. Defaults to None.
- focus(tfrecords)¶
Highlights certain tiles according to a focus list if list provided, or resets highlighting if no tfrecords provided.
- place_tiles(resolution='high', tile_zoom=15, relative_size=False, focus=None, focus_slide=None)¶
Initializes figures and places image tiles.
- Parameters
resolution (str, optional) – Resolution of exported figure; ‘high’, ‘medium’, or ‘low’. Defaults to ‘high’.
tile_zoom (int, optional) – Factor which determines how large individual tiles appear. Defaults to 15.
relative_size (bool, optional) – Physically size grid images in proportion to the number of tiles within the grid space. Defaults to False.
focus (list, optional) – List of tfrecords (paths) to highlight on the mosaic.
- save(filename, **kwargs)¶
Saves the mosaic map figure to the given filename.
- Parameters
filename (str) – Path at which to save the mosiac image.
- Keyword Arguments
resolution (str, optional) – Resolution of exported figure; ‘high’, ‘medium’, or ‘low’. Defaults to ‘high’.
tile_zoom (int, optional) – Factor which determines how large individual tiles appear. Defaults to 15.
relative_size (bool, optional) – Physically size grid images in proportion to the number of tiles within the grid space. Defaults to False.
focus (list, optional) – List of tfrecords (paths) to highlight on the mosaic.
- save_report(filename)¶
Saves a report of which tiles (and their corresponding slide) were displayed on the Mosaic map, in CSV format.
- show()¶
Displays the mosaic map as an interactive matplotlib figure.