Patch Extraction

WSI.patch module


Title: ValidPath Toolbox - patch extraction module

Description: This is the patch extraction module for the ValidPath toolbox. It is includes two classes and several methods

Classes: WSIpatch_extractor, PatchExtractor

Methods: There are two methods in the patch extraction module as follows:

  • PatchExtractor.gen_patch(INPUTDIR: str, PatchSize: tuple, Number_of_Patches: int, intensity_check: boolean, OUTPUTDIR:str)

  • WSIpatch_extractor.patch_extraction(wsi_obj: object, PatchSize: tuple, OUTPUTDIR:str, Random: boolean, Visualize: boolean, Intensity_check: boolean, Number_of_Patches: (int)


class WSI.patch.PatchExtractor[source]

Bases: object

find_between(s, first, last)[source]
gen_patch(INPUTDIR, PatchSize, Number_of_Patches, intensity_check, intensity_threshold, OUTPUTDIR)[source]

This function extracts a number of pactches from extracted annotations. It can save the extracted annottions to the output directory as defined in inputs. Before running this function, please call annotation.ann_extractor.extract_ann(save_dir, XMLs, WSIs) to generate annotations. The output directory will be generated based on the strucutr of the input directories. IF the WSI Magnification is 13X or 20X, this code will automaticall convert to 20X.

Parameters:
INPUTDIRstring

the path to the input directory

PatchSizetuple

the size of image patches to be extracted

Number_of_Patchesint

the number of patches per annotation to be extracted

intensity_checkboolean

to filter the image patches and eliminate empty ones

  • OUTPUTDIR : string the path to the output directory to save image patches

Returns:

Image – extracted image patches from the annotated area.

class WSI.patch.WSIpatch_extractor[source]

Bases: object

patch_extraction(patch_size, output_folder, random_state, visualize, intensity_check, intensity_threshold, std_threshold, patch_number=-1)[source]

this function Generate object for tiles using the DeepZoomGenerator and divided the svs file into tiles of size 256 with no overlap. then processing and saving each tile to local directory.

Parameters:

wsi_objobject

an object containing WSI file and its information

patch_size: integer

the size of image patches to be extracted

output_folderstring

the path to the output directory to save image patches

random_stateboolean

extract patches randomly or in order

visualize: boolean

either to plot extracted patches or not

intensity_check: boolean

to filter the image patches and eliminate empty ones

intensity_threshold: integer

the threshold to include image patches

std_threshold: integer

the standard deviation threhold to include image patches

patch_numberboolean

the number of patches to be extracted. Set to ‘-1’ to extract all possible image patches

patch_extraction_of_tissue(patch_size, output_folder, number_of_patches=1, vis=False)[source]
patch_extraction_with_normalized_tiles(patch_size, output_folder, random_state=True, patch_number=-1)[source]

this function Generate object for tiles using the DeepZoomGenerator and divided the svs file into tiles of size 256 with no overlap. then processing and saving each tile to local directory.

Parameters:

wsi_objobject

WSI object.

patch_size: integer

size tiles

output_folderstring

path root folder to save tiles

perform_segmentation_state: boolean random_state : boolean