Tile¶
The tile
module contains the Tile class to manage a rectangular region cropped from a Slide. A Tile object is described by (i) its extraction coordinates at native magnification (corresponding to level 0 in OpenSlide
), (ii) the level of extraction, (iii) the actual image, stored as a PIL Image. A Tile object will be created internally during the tile extraction process.
- class Tile(image, coords, level=0)[source]¶
Provide Tile object representing a tile generated from a Slide object.
- Parameters
image (PIL.Image.Image) – Image describing the tile
coords (CoordinatePair) – Level 0 Coordinates of the Slide from which the tile was extracted
level (int, optional) – Level of tile extraction, by default 0
- apply_filters(filters)[source]¶
Apply a filter or composition of filters on a tile.
- Parameters
filters (imf.Filter) – Filter or composition of filters to be applied
- Returns
Tile with the filters applied
- Return type
- property coords: histolab.types.CoordinatePair¶
Level 0 Coordinates of the Slide from which the tile was extracted
- Returns
Level 0 Coordinates of the Slide from which the tile was extracted
- Return type
CoordinatePair
- has_enough_tissue(tissue_percent=80.0, near_zero_var_threshold=0.1)[source]¶
Check if the tile has enough tissue.
This method checks if the proportion of the detected tissue over the total area of the tile is above a specified threshold (by default 80%). Internally, the method quantifies the amount of tissue by applying a chain of filters, including conversion to grayscale, Otsu thresholding, binary dilation and small holes filling.
- Parameters
tissue_percent (float, optional) – Number between 0.0 and 100.0 representing the minimum required percentage of tissue over the total area of the image, default is 80.0
near_zero_var_threshold (float, optional) – Minimum image variance after morphological operations (dilation, fill holes), default is 0.1
- Returns
enough_tissue – Whether the image has enough tissue, i.e. if the proportion of tissue over the total area of the image is more than
tissue_percent
and the image variance after morphological operations is more thannear_zero_var_threshold
.- Return type
bool
- property image: PIL.Image.Image¶
Image describing the tile.
- Returns
Image describing the tile.
- Return type
PIL.Image.Image
- property level: int¶
Level of tile extraction.
- Returns
Level of tile extraction.
- Return type
int
- save(path)[source]¶
Save tile at given path.
The format to use is determined from the filename extension (to be compatible to PIL.Image formats). If no extension is provided, the image will be saved in png format.
- Parameters
path (str or pathlib.Path) – Path to which the tile is saved.
- Return type
None
- property tissue_ratio: float¶
Ratio of the tissue area over the total area of the tile.
- Returns
Ratio of the tissue area over the total area of the tile
- Return type
float