WSIReader abstract base class, which standardizes access to Whole Slide Images (WSI). It handles coordinate translations, resolution scaling (Level, Magnification, MPP), and tissue-aware cropping.
Typical usage example: with OpenSlideReader(“path/to/slide.svs”) as reader:
Get tissue-only dimensions
dims = reader.dimensions(bounded=True)Read a region relative to the slide origin
region = reader.read_region((0, 0), (512, 512), Level(0), bounded=False)WSIReader
Path object pointing to the slide file.
Metadata properties extracted from the slide.
open_slide
NotImplementedError— If not implemented by subclass.
level_count
int
Number of pyramid levels.
NotImplementedError— If not implemented by subclass.
mpp
Optional[MPP]
The MPP value if found in metadata, else None.
downsample_dimensions
float
required
The ratio to scale down by.
bool
Whether to return tissue bounds or full slide size.
Union[WSIDims, WSIBounds]
Union[WSIDims, WSIBounds]: Scaled slide dimensions or tissue bounds.
level_dimensions
Level
required
The target pyramid level (0 is highest resolution).
bool
If True, returns tissue area at that level.
Union[WSIDims, WSIBounds]
Union[WSIDims, WSIBounds]: Dimensions or bounds at specified level.
ValueError— If level is out of range.
magnification_dimensions
float
required
Target magnification (e.g., 40x, 20x, 10x).
bool
If True, returns tissue area at that magnification.
Union[WSIDims, WSIBounds]
Union[WSIDims, WSIBounds]: Dimensions or bounds at specified magnification.
mpp_dimensions
float
required
Target microns per pixel.
bool
If True, returns tissue area at that MPP.
Union[WSIDims, WSIBounds]
Union[WSIDims, WSIBounds]: Dimensions or bounds at specified MPP.
dimensions
bool
Acts as the
bounded toggle when a bool.bool
If True, returns tissue bounds.
dimensions
Level
required
Target pyramid level.
bool
If True, returns tissue bounds.
dimensions
Magnification
required
Target optical magnification.
bool
If True, returns tissue bounds.
dimensions
MPP
required
Target microns per pixel.
bool
If True, returns tissue bounds.
dimensions
Resolution
Desired resolution (Level, Magnification, or MPP).
bool
If True, returns tissue area at that resolution.
Union[WSIDims, WSIBounds]
Union[WSIDims, WSIBounds]: Dimensions or bounds at specified resolution.
get_downsample_factor
Resolution
required
The target resolution (Level, Magnification, or MPP).
float
Downsample factor for the given resolution.
level_downsample
int
required
Pyramid level index.
float
Downsample factor for the given level.
NotImplementedError— If not implemented by subclass.
mpp_downsample
float
required
Target microns per pixel.
float
Downsample factor for the target MPP.
ValueError— If metadata is missing or target is too high-res.
magnification_downsample
float
required
Target magnification power.
float
Downsample factor for the target magnification.
ValueError— If metadata is missing or target is out of range.
props
WSIProps
Metadata extracted from the slide.
get_best_level_for_downsample
float
required
Target scaling factor.
int
Best pyramid level index for the downsample.
ValueError— If downsample is too small.
get_downsample_scaling_and_level
Resolution
required
Desired resolution of the slide. Can be one of: - Level: integer pyramid level - Magnification: desired optical magnification - MPP: microns per pixel
tuple
(downsample_factor (float), scaling_factor (float), best_level (int)) - downsample_factor: Factor by which the base level is downsampled. - scaling_factor: Additional scaling needed at the chosen level. - best_level: Pyramid level that best matches the resolution.
ValueError— If required slide properties (objective power or MPP) are unavailable.TypeError— If the resolution type is unsupported.
read_region
tuple[int, int]
required
(x, y) at Level 0.
tuple[int, int]
required
(width, height) at target resolution.
Resolution
required
Resolution level/mpp/magnification.
MeasurementUnit
Unit for the region shape (default pixels).
bool
If True, (0,0) is tissue top-left. Else slide top-left.
Region
Object containing the image and metadata for the requested area.
is_supported_file
bool
True if supported, False otherwise.
NotImplementedError— If not implemented by subclass.
close
NotImplementedError— If not implemented by subclass.
get_thumbnail
tuple[int, int]
required
Max (width, height) for result.
bool
If True, crop to tissue. Else show full slide (incl. white space).
Image.Image
RGB thumbnail image.

