patches¶
errors¶
filters¶
A module to filter patches in a slide.
- exception Error¶
Bases:
ExceptionBase of custom errors.
- standardize_filters(filters, top_level, low_level)¶
Check validity of hierarchical filters.
- Parameters:
filters (
Union[str,Sequence[Sequence[Union[str,Callable]]],Dict[int,Sequence[Sequence[Union[str,Callable]]]]]) – filters to apply. Can be formatted as a single string, a list or a dictionary mapping a level to corresponding filters.top_level (
int) – top pyramid level to consider.low_level (
int) – lowest pyramid level to consider.
- Return type:
Dict[int,Sequence[Sequence[Union[str,Callable]]]]- Returns:
Dictionnary mapping each level to corresponding filters.
- filter_hasdapi(image, dapi_channel=0, tolerance=1)¶
Give presence of dapi in a patch.
- Parameters:
image (
uint8)) – image of a patch.dapi_channel (
int) – channel to extract dapi signal.tolerance (
int) – value on dapi intensity encountered to accept a patch.
- Return type:
bool- Returns:
Whether dapi is visible in slide.
- filter_has_significant_dapi(image, dapi_channel=0, tolerance=0.5, dapi_tolerance=1)¶
Give if enough dapi is present in a patch.
- Parameters:
image (
uint8)) – image of a patch.dapi_channel (
int) – channel to extract dapi signal.tolerance (
float) – part of the patch that must contain dapi.dapi_tolerance (
int) – value on dapi intensity encountered to accept a patch.
- Return type:
bool- Returns:
Whether dapi is significantally visible in slide.
- get_tissue_from_rgb(image, blacktol=0, whitetol=230)¶
Return the tissue mask segmentation of an image.
True pixels for the tissue, false pixels for the background.
- Parameters:
image (
uint8)) – image of a patch.blacktol (
Union[float,int]) – tolerance value for black pixels.whitetol (
Union[float,int]) – tolerance value for white pixels.
- Return type:
bool8)- Returns:
Mask where true pixels are tissue, false are background.
- get_tissue_from_lab(image, blacktol=5, whitetol=90)¶
Get the tissue mask segmentation of an image.
This version operates in the lab space, conversion of the image from rgb to lab is performed first.
- Parameters:
image (
uint8)) – image of a patch.blacktol (
Union[float,int]) – tolerance value for black pixels.whitetol (
Union[float,int]) – tolerance value for white pixels.
- Return type:
bool8)- Returns:
Mask where true pixels are tissue, false are background.
- get_tissue(image, blacktol=5, whitetol=90, method='lab')¶
Get the tissue mask segmentation of an image.
One can choose the segmentation method.
- Parameters:
image (
uint8)) – image of a patch.blacktol (
Union[float,int]) – tolerance value for black pixels.whitetol (
Union[float,int]) – tolerance value for white pixels.method (
str) – one of ‘lab’ or ‘rgb’, function to be called.
- Return type:
bool8)- Returns:
Mask where true pixels are tissue, false are background.
- filter_has_tissue_he(image, blacktol=5, whitetol=90)¶
Return true if tissue inside the patch.
Filters tissue using the l channel from lab space. Conversion of the image from rgb to lab is performed first.
- Parameters:
image (
uint8)) – image of a patch.blacktol (
Union[float,int]) – tolerance value for black pixels.whitetol (
Union[float,int]) – tolerance value for white pixels.
- Return type:
bool- Returns:
True if tissue is detected.
functional_api¶
object_api¶
slide_filters¶
- filter_remove_small_objects(in_mask, avoid_overmask=True, overmask_thresh=10, min_size_fac=1)¶
Removes small objects from a binary mask. Can recursively lowers its minimum accepted size if too much tissue is erased.
- Parameters:
in_mask (
bool8)) – input binary mask (must be boolean).avoid_overmask (
bool) – if True recursively call itself if too much tissue is erased.overmask_thresh (
float) – if avoid_overmask and more than overmask_thresh% of the input mask is erased, calls the function recursively with lower minimum accepted size.min_size_fac (
float) – multiplier for overmask_thresh used to compute minimum accepted size. Mainly for internal use in recursive call.
- Return type:
bool8)- Returns:
Output binary mask with small objects removed.
- filter_thumbnail(x)¶
Compute a tissue mask from a slide thumbnail.
Filters background, red pen, blue pen using La*b* space.
- Parameters:
x (
uint8)) – input thumbnail as a numpy byte array.- Return type:
bool8)- Returns:
Numpy binary mask where usable tissue is marked as True.
- filter_fluo_thumbnail(x, channel=2)¶
Compute a tissue mask from a fluorescent slide thumbnail.
Filters empty regions using otsu operator.
- Parameters:
x (
uint8)) – input thumbnail as a numpy byte array.channel (
int) – fluorescent channel to perform threshold on, default is 2 for blue <=> dapi.
- Return type:
bool8)- Returns:
Numpy binary mask where usable tissue is marked as True.
- get_json2pathaia_filter(annotfile, label)¶
Get a slide_filter corresponding to annotations in Micromap format for a specific class. This filter will only keep patches that have the corresponding label.
- Parameters:
annotfile (
Union[str,PathLike]) – Path to annotation file for this slide.label (
str) – annotation label that is supposed to be positive.
- Returns:
Numpy binary mask where annotated tissue is marked as True.
visu¶
Useful functions for visualizing patches in WSIs.
- preview_from_queries(slide, queries, min_res=512, color=(255, 255, 0), thickness=2, cell_size=20, size_0=None)¶
Give thumbnail with patches displayed.
- Parameters:
slide (
OpenSlide) – openslide objectqueries (
Sequence[Patch]) – patch objects to preview frommin_res (
int) – minimum size for the smallest side of the thumbnail (usually the width)color (
Tuple[int,int,int]) – rgb color for patch boundariesthickness (
int) – thickness of patch boundariescell_size (
int) – size of a cell representing a patch in the gridpsize – size of a patch at level 0
- Return type:
uint8)- Returns:
Thumbnail image with patches displayed.