Tissue Detection

Created on Wed Sep 18 03:29:24 2019.

@author: mtageld

histomicstk.saliency.tissue_detection.get_slide_thumbnail(gc, slide_id)[source]

Get slide thumbnail using girder client.

Parameters:
  • gc (object) – girder client to use

  • slide_id (str) – girder ID of slide

Returns:

RGB slide thumbnail at lowest level

Return type:

np array

histomicstk.saliency.tissue_detection.get_tissue_boundary_annotation_documents(gc, slide_id, labeled, color='rgb(0,0,0)', group='tissue', annprops=None)[source]

Get annotation documents of tissue boundaries to visualize on DSA.

Parameters:
  • gc (object) – girder client to use

  • slide_id (str) – girder ID of slide

  • labeled (np array) – mask of tissue regions using slide thumbnail. This could either be a binary mask or a mask where each unique value corresponds to one tissue region. It will be binalized anyways. This can be obtained using get_tissue_mask().

  • color (str) – color to assign to boundaries. format like rgb(0,0,0)

  • group (str) – label for annotations

  • annpops (dict) – properties of annotation elements. Contains the following keys F, X_OFFSET, Y_OFFSET, opacity, lineWidth. Refer to get_single_annotation_document_from_contours() for details.

Returns:

each dict is an annotation document that you can post to DSA

Return type:

list of dicts

histomicstk.saliency.tissue_detection.get_tissue_mask(thumbnail_im, deconvolve_first=False, stain_unmixing_routine_kwargs=None, n_thresholding_steps=1, sigma=0.0, min_size=500)[source]

Get binary tissue mask from slide thumbnail.

Parameters:
  • thumbnail_im (np array) – (m, n, 3) nd array of thumbnail RGB image or (m, n) nd array of thumbnail grayscale image

  • deconvolve_first (bool) – use hematoxylin channel to find cellular areas? This will make things ever-so-slightly slower but is better in getting rid of sharpie marker (if it’s green, for example). Sometimes things work better without it, though.

  • stain_matrix_method (str) – see deconv_color method in seed_utils

  • n_thresholding_steps (int) – number of gaussian smoothing steps

  • sigma (float) – sigma of gaussian filter

  • min_size (int) – minimum size (in pixels) of contiguous tissue regions to keep

Returns:

  • np int32 array – each unique value represents a unique tissue region

  • np bool array – largest contiguous tissue region.

histomicstk.saliency.tissue_detection.threshold_multichannel(im, thresholds, channels=None, just_threshold=False, get_tissue_mask_kwargs=None)[source]

Threshold a multi-channel image (eg. HSI image) to get tissue.

The relies on the fact that oftentimes some slide elements (eg blood or whitespace) have a characteristic hue/saturation/intensity. This thresholds along each HSI channel, then optionally uses the get_tissue_mask() method (gaussian smoothing, otsu thresholding, connected components) to get each contiguous tissue piece.

Parameters:
  • im (np array) – (m, n, 3) array of Hue, Saturation, Intensity (in this order)

  • thresholds (dict) – Each entry is a dict containing the keys min and max

  • channels (list) – names of channels, in order (eg. hue, saturation, intensity)

  • just_threshold (bool) – if False, get_tissue_mask() is used to smooth result and get regions.

  • get_tissue_mask_kwargs (dict) – key-value pairs of parameters to pass to get_tissue_mask()

Returns:

  • np int32 array – if not just_threshold, unique values represent unique tissue regions

  • np bool array – if not just_threshold, largest contiguous tissue region.