Skip to main content
WSI Reader Base Module. This module provides the 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

Abstract Base Class for all WSI Backends. Standardizes the interface for reading digital pathology slides across different vendors. It manages metadata, pyramid levels, and tissue bounding box transformations.
Path object pointing to the slide file.
Metadata properties extracted from the slide.

open_slide

Opens the file handle for the slide. Raises:
  • NotImplementedError — If not implemented by subclass.

level_count

Number of pyramid levels available in the slide.
int
Number of pyramid levels.
Raises:
  • NotImplementedError — If not implemented by subclass.

mpp

Native microns per pixel (MPP) value.
Optional[MPP]
The MPP value if found in metadata, else None.
Example:

downsample_dimensions

Calculates slide dimensions at a specific downsample factor.
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.
Example:

level_dimensions

Returns the dimensions of a specific pyramid level.
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.
Raises:
  • ValueError — If level is out of range.
Example:

magnification_dimensions

Returns slide dimensions for a specific optical magnification.
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.
Example:

mpp_dimensions

Returns slide dimensions for a specific MPP (microns per pixel).
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.
Example:

dimensions

Returns full or bounded slide dimensions at Level 0.
bool
Acts as the bounded toggle when a bool.
bool
If True, returns tissue bounds.

dimensions

Returns slide dimensions at a pyramid level.
Level
required
Target pyramid level.
bool
If True, returns tissue bounds.

dimensions

Returns slide dimensions at a magnification.
Magnification
required
Target optical magnification.
bool
If True, returns tissue bounds.

dimensions

Returns slide dimensions at a target MPP.
MPP
required
Target microns per pixel.
bool
If True, returns tissue bounds.

dimensions

Returns slide dimensions for a specific resolution.
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.
Example:

get_downsample_factor

Calculates the downsample factor for a given resolution.
Resolution
required
The target resolution (Level, Magnification, or MPP).
float
Downsample factor for the given resolution.
Example:

level_downsample

Returns downsample factor for a pyramid level.
int
required
Pyramid level index.
float
Downsample factor for the given level.
Raises:
  • NotImplementedError — If not implemented by subclass.

mpp_downsample

Calculates downsample needed for target MPP.
float
required
Target microns per pixel.
float
Downsample factor for the target MPP.
Raises:
  • ValueError — If metadata is missing or target is too high-res.
Example:

magnification_downsample

Calculates downsample needed for target magnification.
float
required
Target magnification power.
float
Downsample factor for the target magnification.
Raises:
  • ValueError — If metadata is missing or target is out of range.
Example:

props

Slide metadata properties.
WSIProps
Metadata extracted from the slide.
Example:

get_best_level_for_downsample

Finds highest pyramid level smaller than target downsample factor.
float
required
Target scaling factor.
int
Best pyramid level index for the downsample.
Raises:
  • ValueError — If downsample is too small.
Example:

get_downsample_scaling_and_level

Determine the downsample factor, scaling factor, and best pyramid level for a given resolution.
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.
Raises:
  • ValueError — If required slide properties (objective power or MPP) are unavailable.
  • TypeError — If the resolution type is unsupported.
Example:

read_region

Reads a region from the slide.
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.
Example:

is_supported_file

Checks if backend supports this file extension.
bool
True if supported, False otherwise.
Raises:
  • NotImplementedError — If not implemented by subclass.

close

Closes slide file handle. Returns: None Raises:
  • NotImplementedError — If not implemented by subclass.

get_thumbnail

Generates a slide 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.
Example: