module documentation

Undocumented

Function autogain_background Automatically set pixels around the background mean to maximum white.
Function colourmap_1d Linear map an array of 1d floats between two tristimulus values.
Function colourmap_veridis Linear map an array of 1d floats between to the veridis colour map
Function create_colourised_density_map Create a colourised, spatially filtered density image, with overlayed map
Function generate_densities_and_map_coordinates Produces density maps for a given decomposed image, and areas above a signal and classification threshold
Function hitbox Draw a hit-box around the edge of an image or image segment
Function hitbox_rgb_image For a given image and set of coordinates, draw the hitox for those coordinates
Function normalise Normalise an array, centreing it on 0.5
Function process_file Process an SVS file, loading, decomposing and producing density maps
Function process_files_and_folders Main routine for running this module as a command line function. This routine produces density maps, segmentation images and structured json output for a folder or single SVS file.
Function return_spectral_image Spectral Estimation Image of Stains from Aperio Microscope
Function spatial_map_3b3 Apply a spatial convolutional kernel to im
Function write_region_image Dump ROIs to disk
def autogain_background(image, xin=(200, -100), yin=(100, 200), threshold=0.95, channel=0, value=255):

Automatically set pixels around the background mean to maximum white.

Parameters
imageNxMx3 loaded image (3d np.array)
xinthe x coordinates to estimate the background
yinthe y coordinates to estimate the background
thresholdthe lower bound around the mean for which pixels will be treated as background (default .95/95%)
channelthe channel to test, by default 0 (RED) as this is not a signal channel
valuethe value to set the R, G and B components to, by default max white (255, 255, 255)
Returns
NxM image with gain adjustment.
def colourmap_1d(colour1, colour2, one_d_floats):

Linear map an array of 1d floats between two tristimulus values.

Parameters
colour11x3 RGB Value (np.array)
colour21x3 RGB Value (np.array)
one_d_floatsarray of floats between 0 and 1 (np.array)
Returns
transformed values (NX3 => colour1 < Im < colour2)
def colourmap_veridis(one_d_floats):

Linear map an array of 1d floats between to the veridis colour map

Parameters
one_d_floatsarray of floats between 0 and 1 (np.array)
Returns
transformed values (NX3 => veridis(0) < Im < veridis(1))
def create_colourised_density_map(raw, raw_threshold, densities, stride, class_threshold, identify_rois=False):

Create a colourised, spatially filtered density image, with overlayed map

Parameters
rawraw decomposed image
raw_thresholddensity map threshold
densitiesdensities array produced by generate_densities_and_map_coordinates
stridestride over which to tumble
class_thresholdclassification threshold for ROIs
identify_roisOverlay ROI's of significant density
Returns
reduced_brightness_density_map, density_mapp_array
def generate_densities_and_map_coordinates(raw_image, stride, raw_threshold, class_threshold):

Produces density maps for a given decomposed image, and areas above a signal and classification threshold

Definitions

Definitions of terms used in procedure below:

    I : [DAB Image],  i : [rows of image], j: [columns of image]
    D : [Density Map], s: [Stride], si: [i / stride], sj: [j / stride]
    B : [Binary map], T : [Signal Threshold], C: [Classification Threshold]
    mu : [Array mean], R : [ROI Array], O: [Coordinates array], Om: [Map Coordinates Array]

Procedure

Pseudocode for procedure generating density maps:

    B(i,j) = I(i,j) < T
    D(si, sj) = mu(I(i:i+s, j:j+s))
    R(si, sj) = D > C
    Om = (si, sj) for si and sj if R(si, sj)
    O = (i, j) for i and j if R(i / stride, j / stride)
Parameters
raw_imageNxMxF spectral image, where F is the number of channels (Fd np.array)
strideThe window size over which we will tumble
raw_thresholdThe value per pixel to be considered a 'vote' for that pixel containing significant signal
class_thresholdThe mean density required for that region to be considered an ROI
Returns
NxM densities array, coordinates in the image of ROIs, coordinates in the map of ROIs (np.arrays)
def hitbox(im_to_hit):

Draw a hit-box around the edge of an image or image segment

Parameters
im_to_hitarray or array slice (3d np.array)
Returns
None, inplace
def hitbox_rgb_image(image, coordinates, stride):

For a given image and set of coordinates, draw the hitox for those coordinates

Parameters
imagearray or array slice (3d np.array)
coordinatescoordinates array referencing y, x location in image
stridesize of hitbox in px
Returns
image (although it is applied in place)
def normalise(a):

Normalise an array, centreing it on 0.5

Parameters
aArray in (np.array NxM)
Returns
transformed values (NxM => 0 < F < 1)
def process_file(file, stride, raw_threshold, class_threshold, apply_automatic_background_removal, microns=2.0, verbose=False):

Process an SVS file, loading, decomposing and producing density maps

Parameters
filefullpath to SVS file
strideThe window size over which we will tumble
raw_thresholdThe value per pixel to be considered a 'vote' for that pixel containing significant signal
class_thresholdThe mean density required for that region to be considered an ROI
apply_automatic_background_removalattempt to remove the slide background
micronsSlide resolution in um per pixel, default 2.0um
verboseprovide printed output
Returns
image, raw_image (decomposed), densities, coordinates, map_coordinates
def process_files_and_folders(input_file_or_folder, output_folder, stride=512, raw_threshold=-0.1, class_threshold=0.1, output_density=False, output_json=False, skip_jpeg=False, auto_remove_background=True, include_only_index=None, output_segmentation=False, verbose=True, synthetic=False):

Main routine for running this module as a command line function. This routine produces density maps, segmentation images and structured json output for a folder or single SVS file.

Parameters
input_file_or_folderFull path to SVS file, or folder filled with SVS files
output_folderFull path of the folder to output results {json, jpegs}
strideStride over which to tumble
raw_thresholdDensity difference under which we will consider the signal a valid signal
class_thresholdMean density identification threshold required to specify an ROI
output_densityShould density images be saved to disk {jpegs}
output_jsonShould json metadata/density maps be saved to disk {json}
skip_jpegSkip saving the ROI hit-boxed images to disk
auto_remove_backgroundShould we apply automatic background identification and removal
include_only_indexFilter filenames for string, (e.g. "17_A") when not None
output_segmentationOutput each ROI as an image {jpegs}
verboseprintf feedback
syntheticShould we look for JPG files
Returns
None
def return_spectral_image(image):

Spectral Estimation Image of Stains from Aperio Microscope

Parameters
imageNxMx3 loaded image (3d np.array)
Returns
NxM DAB response image
def spatial_map_3b3(im):

Apply a spatial convolutional kernel to im

Parameters
imNxM image (2d or 3d np.array)
Returns
filter image by convolutional kernel
def write_region_image(parent_path, filename_prefix, coordinates, image, stride):

Dump ROIs to disk

Parameters
parent_pathroot folder of images
filename_prefixname of the collection of images (e.g. slide name)
coordinatescoordinates of the start x,y of the regions
imageimage to traverse
stridestride over which to tumble
Returns
None