Finding cellular regions with superpixel analysis

Created on Mon Sep 23 21:17:43 2019.

@author: mtageld

class histomicstk.saliency.cellularity_detection_superpixels.CD_single_tissue_piece(cd, tissue_mask, monitorPrefix='')[source]

Bases: object

Detect cellular regions in a single tissue piece (internal).

assign_cellularity_scores()[source]

Assign cellularity scores to spixel clusters.

assign_colors_to_spixel_clusters()[source]

Assign RGB color string to cellularity clusters.

restrict_mask_to_single_tissue_piece()[source]

Only keep relevant part of slide mask.

run()[source]

Get cellularity and optionally visualize on DSA.

set_superpixel_assignment()[source]

Fit gaussian mixture model to features and get assignment.

set_superpixel_features()[source]

Get superpixel features.

set_superpixel_mask()[source]

Use Simple Linear Iterative Clustering (SLIC) to get superpixels.

set_tissue_rgb()[source]

Load RGB from server for single tissue piece.

visualize_contiguous_superpixels()[source]

Visualize contiguous spixels, color-coded by cellularity.

visualize_individual_superpixels()[source]

Visualize individual spixels, color-coded by cellularity.

class histomicstk.saliency.cellularity_detection_superpixels.Cellularity_detector_superpixels(gc, slide_id, **kwargs)[source]

Bases: Base_HTK_Class

Detect cellular regions in a slides by classifying superpixels.

This uses Simple Linear Iterative Clustering (SLIC) to get superpixels at a low slide magnification to detect cellular regions. The first step of this pipeline detects tissue regions (i.e. individual tissue pieces) using the get_tissue_mask method of the histomicstk.saliency module. Then, each tissue piece is processed separately for accuracy and disk space efficiency. It is important to keep in mind that this does NOT rely on a tile iterator, but loads the entire tissue region (but NOT the whole slide) in memory and passes it on to skimage.segmentation.slic method.

Once superpixels are segmented, the image is deconvolved and features are extracted from the hematoxylin channel. Features include intensity and possibly also texture features. Then, a mixed component Gaussian mixture model is fit to the features, and median intensity is used to rank superpixel clusters by ‘cellularity’ (since we are working with the hematoxylin channel).

Additional functionality includes contour extraction to get the final segmentation boundaries of cellular regions and to visualize them in DSA using one’s preferred colormap.

run()[source]

Run cellularity detection and optionally visualize result.

This runs the cellularity detection +/- visualization pipeline and returns a list of CD_single_tissue_piece objects. Each object has the following attributes

tissue_masknp array

mask of where tissue is at target magnification

yminint

min y coordinate at base (scan) magnification

xminint

min x coordinate at base (scan) magnification

ymaxint

max y coordinate at base (scan) magnification

xmaxint

max x coordinate at base (scan) magnification

spixel_masknp array

np array where each unique value represents one superpixel

fdatapandas DataFrame

features extracted for each superpixel. Index corresponds to values in the spixel_mask. This includes a ‘cluster’ column indicatign which cluster this superpixel belongs to.

cluster_propsdict

properties of each superpixel cluster, including its assigned cellularity score.

set_color_normalization_values(mu=None, sigma=None, ref_image_path=None, what='main')[source]

Set color normalization values for thumbnail or main image.

set_slide_info_and_get_tissue_mask()[source]

Set self.slide_info dict and self.labeled tissue mask.