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 to spixel clusters.


Assign RGB color string to cellularity clusters.


Only keep relevant part of slide mask.


Get cellularity and optionally visualize on DSA.


Fit gaussian mixture model to features and get assignment.


Get superpixel features.


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


Load RGB from server for single tissue piece.


Visualize contiguous spixels, color-coded by cellularity.


Visualize individual spixels, color-coded by cellularity.

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

Bases: histomicstk.utils.general_utils.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 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


min y coordinate at base (scan) magnification


min x coordinate at base (scan) magnification


max y coordinate at base (scan) magnification


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.


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 self.slide_info dict and self.labeled tissue mask.