Color thresholding semantic segmentation

Created on Tue Oct 22 02:37:52 2019.

@author: mtageld

class histomicstk.saliency.cellularity_detection_thresholding.CDT_single_tissue_piece(cdt, tissue_mask, monitorPrefix='')[source]

Bases: object

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


Get components by thresholding in HSI and LAB spaces.


Color normalize “true” tissue components.


Find regions that are potentially cellular.


Keep largest and most cellular regions.


Initialize labeled components mask.


Only keep relevant part of slide mask.


Get cellularity and optionally visualize on DSA.


Load RGB from server for single tissue piece.


Visualize results in DSA.

class histomicstk.saliency.cellularity_detection_thresholding.Cellularity_detector_thresholding(gc, slide_id, GTcodes, **kwargs)[source]

Bases: histomicstk.utils.general_utils.Base_HTK_Class

Detect cellular regions in a slide using thresholding.

This uses a thresholding and stain unmixing based pipeline to detect highly-cellular regions in a slide. The run() method of the CDT_single_tissue_piece() class has the key steps of the pipeline. In summary, here are the steps involved…

1. Detect tissue from background using the RGB slide thumbnail. Each “tissue piece” is analysed independently from here onwards. The tissue_detection modeule is used for this step. A high sensitivity, low specificity setting is used here.

2. Fetch the RGB image of tissue at target magnification. A low magnification (default is 3.0) is used and is sufficient.

3. The image is converted to HSI and LAB spaces. Thresholding is performed to detect various non-salient components that often throw-off the color normalization and deconvolution algorithms. Thresholding includes both minimum and maximum values. The user can set whichever thresholds of components they would like. The development of this workflow was focused on breast cancer so the thresholded components by default are whote space (or adipose tissue), dark blue/green blotches (sharpie, inking at margin, etc), and blood. Whitespace is obtained by thresholding the saturation and intensity, while other components are obtained by thresholding LAB.

4. Now that we know where “actual” tissue is, we do a MASKED color normalization to a prespecified standard. The masking ensures the normalization routine is not thrown off by non- tissue components.

5. Perform masked stain unmixing/deconvolution to obtain the hematoxylin stain channel.

6. Smooth and threshold the hematoxylin channel. Then perform connected component analysis to find contiguous potentially-cellular regions.

7. Keep the n largest potentially-cellular regions. Then from those large regions, keep the m brightest regions (using hematoxylin channel brightness) as the final salient/cellular regions.


Fix self.GTcodes (important!).


Run full pipeline to detect cellular regions.

set_color_normalization_target(ref_image_path, color_normalization_method='macenko_pca')[source]

Set color normalization values to use from target image.

Arguments ref_image_path, str > path to target (reference) image color_normalization_method, str > color normalization method to use. Currently, only > reinhard and macenko_pca are accepted.


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