PyHistopathology

PyHistopathology is a Python API for pre-processing Whole-Slide Images for use in a machine learning algorithm.

Features

Reading Whole-Slide Images with WSI_Scanning.readWSI()

  • Input: WSI path or directory
  • Output: Numpy array of WSI with data type int32

Denoising Whole-Slide Images with Denoising.denoising()

  • Input: WSI Path or directory
  • Output: Numpy array of WSI Image (After denoising) with dtype int32

Patch Extraction for Whole-Slide Images with Extractingpatches.extractingPatches()

  • Input: WSI Path or directory
  • Output: Fills up the outputpath with patches extracted from the WSI

Table of Contents

Reading

Use WSI_Scanning.readWSI() to read Whole-Slide Images

Usage

readWSI(WSI_path, magnification_level, annotation_file, annonated_level)

Arguments

WSI_path

Path or location of WSI.

magnification_level

Level of zoom, for example 40, 20, 10, or 5. Default magnification level is 20. - Note: if magnification 40x for max zoom level of 20x image an error will be raised.

annotation_file

Default annotation = None. If annotation are available in a xml file, set annotation_file to be the xml file path.

annonated_level

If annotation is given then set annotated_level equal to the z-axis of the annotations. Default annotatedlevel is 0.

Return Type

Numpy array of WSI Image (After denoising) with dtype int32

Example

from WSI_Preprocessing.Preprocessing import WSI_Scanning
import cv2
img,slide_dim = WSI_Scanning.readWSI("example.svs")
cv2.imwrite("example.png",img)

Denoising

Use Denoising.denoising() to remove stains, folds and other background noise in Whole-Slide Images

Usage

denoising(inputsvs, magnification, filtering, patch_size, upperlimit, lowerlimit, red_value, green_value, blue_value)

Arguments

inputsvs

Path or location of WSI.

magnification

Level of zoom, for example 40, 20, 10, or 5. Default magnification level is 20. - Note: if magnification 40x for max zoom level of 20x image an error will be raised.

filtering

GuassianBlur, RGBThersholding, or None

GuassianBlur: Homogeneity calculations based on image smoothing and Gaussian blur equations. We compute sum of square differences between two consecutive Gaussian blurred images as score for homogeneity.

  • Upper limit: Upper threshold of homogeneity score. Default value is 9500 with kernel size of 1111
  • Lower limit: lower threshold of homogeneity score. default value is 1500 with kernel size of 1111
  • Patch size: Not significant parameters for GuassianBlur filtering

RGBThersholding: Validated patches based on RGB values of patches

  • red_value: Red threshold
  • green-value: Green threshold
  • blue_value: Blue Threshold

None: Only removes Background

Note that our default is GuassianBlur technique. GuassianBlur is highly effective and requires more computational power (RAM). RGBThersholding is less effective which needs less computational power

Return Type

Numpy array of WSI Image (After denoising) with dtype int32

Extracting

Use Extractingpatches.extractingPatches() to extract patches from Whole-Slide Images

Usage

extractingPatches(inputsvs, outputpath, magnification, patch_extraction_creatia, number_of_patches, filtering, patch_size, upperlimit, lowerlimit, red_value, green_value, blue_value, Annotation, Annotationlevel, Requiredlevel, reconstructionimagepath)

Arguments

inputsvs

Path or location of WSI.

magnification

Level of zoom, for example 40, 20, 10, or 5. Default magnification level is 20. - Note: if magnification 40x for max zoom level of 20x image an error will be raised.

filtering

GuassianBlur, RGBThersholding, or None

GuassianBlur: Homogeneity calculations based on image smoothing and Gaussian blur equations. We compute sum of square differences between two consecutive Gaussian blurred images as score for homogeneity.

  • Upper limit: Upper threshold of homogeneity score. Default value is 9500 with kernel size of 1111
  • Lower limit: lower threshold of homogeneity score. default value is 1500 with kernel size of 1111
  • Patch size: Not significant parameters for GuassianBlur filtering

RGBThersholding: Validated patches based on RGB values of patches

  • red_value: Red threshold
  • green-value: Green threshold
  • blue_value: Blue Threshold

None: Only removes Background

Note that our default is GuassianBlur technique. GuassianBlur is highly effective and requires more computational power (RAM). RGBThersholding is less effective which needs less computational power

patch_extraction_creatia

random, or None. Default is None. For extracting a fixed number of patches for WSI we can use random.

number_of_patches

Default number of patches is 2000

outputpath

Folder to store the extracted patches

reconstructionimagepath

If you want to compare the patches with WSI we can mention the reconstructionimagepath. Default is None. Note: it only works with patch_extraction_creatia = None.

Return Type

None, fills up output path with images directly instead of returning a Numpy array.