Skip to main content
WSI Data & Dataset Module. Provides WSIData (single-slide wrapper) and WSIDataset (multi-slide collection) that bridge the bioptimus I/O + extraction layers into structures ready for feature extraction or training. Typical usage:

WSIData

Wraps a single Whole Slide Image with its extraction plan. On construction the slide is opened via WSI and the extractor is fitted + executed to produce a list of RegionSpec. Each spec describes one tile/patch location. Patches are read lazily via get_patch.
Path to the WSI file (any format supported by WSI).
A configured TileExtractor. A fresh fit_extract is called for every slide so the same extractor object can be reused across slides.
Optional callable applied to the raw np.ndarray patch before it is returned. Receives (H, W, C) uint8 and should return a transformed array (or tensor).
Path
Resolved slide path.
WSIReader
Open reader for the slide.
List[RegionSpec]
Extraction plan (one entry per patch).
str
Stem of the slide filename.
Example:

get_patch

Reads a single patch from the slide.
int
required
Index into specs.
Tuple[Any, Dict[str, Any]]
A tuple (patch, metadata) where patch is an np.ndarray of shape (H, W, C) (or whatever the transform returns), and metadata is a dict with at minimum source, x, y, width, height, slide_name, and tissue_ratio.
Raises:
  • IndexError — If idx is out of range.

close

Closes the underlying WSI reader and releases resources. Example:

WSIDataset

A collection of WSIData wrappers with flat patch indexing. Supports two access patterns:
  • Slide-leveldataset.slides[i] returns a WSIData.
  • Patch-level (flat) — dataset[k] maps a global patch index across all slides and returns (patch, metadata).
The flat indexing uses a cumulative-sum lookup (O(log N) via bisect) so random access is fast regardless of how many slides are loaded.
Pre-built WSIData instances.
Example:

from_paths

Creates a dataset by opening and extracting every slide.
Sequence[Union[str, Path]]
required
Iterable of WSI file paths.
TileExtractor
required
Shared TileExtractor (re-fitted per slide).
Optional[Callable[[np.ndarray], Any]]
Optional callable applied to each extracted tile array.
WSIDataset
A new WSIDataset.
Example:

num_slides

Returns the number of loaded slides.
int
Slide count.
Example:

slide_patch_counts

Returns a mapping of slide names to their patch counts.
Dict[str, int]
Dict[str, int]: {slide_name: patch_count} for every slide.
Example:

close

Closes all underlying WSI readers. Example: