glasscut.slides.backends package¶
Submodules¶
glasscut.slides.backends.base module¶
Abstract backend interface for slide reading.
- class glasscut.slides.backends.base.SlideBackend[source]¶
Bases:
ABCAbstract base class for slide reading backends.
This defines the interface that all slide backends must implement. Backends handle the actual reading of slide files and tile extraction.
- abstractmethod open(path)[source]¶
Open a slide file.
- Parameters:
path (str | Path) – Path to the slide file
- Return type:
None
- abstract property num_levels: int¶
Get number of pyramid levels.
- Returns:
Number of pyramid levels
- Return type:
- abstractmethod get_thumbnail(size)[source]¶
Get thumbnail of the slide.
- abstract property mpp: float¶
Get microns per pixel at base magnification.
- Returns:
Microns per pixel
- Return type:
- Raises:
SlidePropertyError – If MPP cannot be determined from slide metadata
- abstract property base_magnification: int | float¶
Get the base magnification (objective power) of the slide.
This is the magnification at level 0 (highest resolution). For example, 40x, 20x, 10x, etc.
- Returns:
Base magnification value
- Return type:
- Raises:
SlidePropertyError – If base magnification cannot be determined from slide metadata
- __exit__(exc_type, exc_val, exc_tb)[source]¶
Context manager exit.
- Parameters:
exc_type (type[BaseException] | None)
exc_val (BaseException | None)
exc_tb (TracebackType | None)
- Return type:
None
glasscut.slides.backends.cucim_backend module¶
CuCim backend for GPU-accelerated slide reading.
- class glasscut.slides.backends.cucim_backend.CuPyArrayProtocol(*args, **kwargs)[source]¶
Bases:
ProtocolProtocol for CuPy GPU arrays with NumPy-like interface.
- __init__(*args, **kwargs)¶
- class glasscut.slides.backends.cucim_backend.CuImageProtocol(*args, **kwargs)[source]¶
Bases:
ProtocolProtocol describing the interface of cucim.CuImage objects.
- read_region(location, level, size)[source]¶
Read a region from the image at specified level.
Returns a CuPy array or NumPy array.
- __init__(*args, **kwargs)¶
- class glasscut.slides.backends.cucim_backend.CuCimBackend[source]¶
Bases:
SlideBackendCuCim-based backend for GPU-accelerated slide reading.
This backend uses RAPIDS cuCim for high-performance GPU-accelerated reading of whole slide images. Falls back to OpenSlide for metadata and operations not supported by cuCim.
- open(path)[source]¶
Open a slide file using CuCim.
- Parameters:
path (str | Path) – Path to the slide file
- Raises:
FileNotFoundError – If the slide file does not exist
BackendError – If cuCim cannot open the file
- Return type:
None
- property properties: dict[str, str]¶
Get slide metadata properties.
Falls back to OpenSlide for metadata retrieval.
- property num_levels: int¶
Get number of pyramid levels.
Falls back to OpenSlide for level information.
- Returns:
Number of pyramid levels
- Return type:
- read_region(location, level, size)[source]¶
Read a region/tile from the slide using GPU acceleration.
- get_thumbnail(size)[source]¶
Get thumbnail of the slide.
Falls back to OpenSlide if available.
- property mpp: float¶
Get microns per pixel at base magnification.
Falls back to OpenSlide for metadata retrieval.
- Returns:
Microns per pixel (MPP)
- Return type:
- Raises:
SlidePropertyError – If MPP cannot be determined from metadata
glasscut.slides.backends.openslide_backend module¶
OpenSlide backend for slide reading (CPU-based).
- class glasscut.slides.backends.openslide_backend.OpenSlideBackend[source]¶
Bases:
SlideBackendOpenSlide-based backend for reading whole slide images.
This is the CPU-based fallback backend. It uses the OpenSlide library to read various slide formats (SVS, TIFF, etc.).
- open(path)[source]¶
Open a slide file using OpenSlide.
- Parameters:
path (Union[str, Path]) – Path to the slide file
- Raises:
FileNotFoundError – If the slide file does not exist
BackendError – If OpenSlide cannot open the file
- Return type:
None
- property num_levels: int¶
Get number of pyramid levels.
- Returns:
Number of pyramid levels
- Return type:
- get_thumbnail(size)[source]¶
Get thumbnail of the slide.
- property mpp: float¶
Get microns per pixel at base magnification.
- Returns:
Microns per pixel (MPP)
- Return type:
- Raises:
SlidePropertyError – If MPP cannot be determined from metadata
Module contents¶
Slide reading backends.
- class glasscut.slides.backends.SlideBackend[source]¶
Bases:
ABCAbstract base class for slide reading backends.
This defines the interface that all slide backends must implement. Backends handle the actual reading of slide files and tile extraction.
- abstractmethod open(path)[source]¶
Open a slide file.
- Parameters:
path (str | Path) – Path to the slide file
- Return type:
None
- abstract property num_levels: int¶
Get number of pyramid levels.
- Returns:
Number of pyramid levels
- Return type:
- abstractmethod get_thumbnail(size)[source]¶
Get thumbnail of the slide.
- abstract property mpp: float¶
Get microns per pixel at base magnification.
- Returns:
Microns per pixel
- Return type:
- Raises:
SlidePropertyError – If MPP cannot be determined from slide metadata
- abstract property base_magnification: int | float¶
Get the base magnification (objective power) of the slide.
This is the magnification at level 0 (highest resolution). For example, 40x, 20x, 10x, etc.
- Returns:
Base magnification value
- Return type:
- Raises:
SlidePropertyError – If base magnification cannot be determined from slide metadata
- __exit__(exc_type, exc_val, exc_tb)[source]¶
Context manager exit.
- Parameters:
exc_type (type[BaseException] | None)
exc_val (BaseException | None)
exc_tb (TracebackType | None)
- Return type:
None
- class glasscut.slides.backends.OpenSlideBackend[source]¶
Bases:
SlideBackendOpenSlide-based backend for reading whole slide images.
This is the CPU-based fallback backend. It uses the OpenSlide library to read various slide formats (SVS, TIFF, etc.).
- open(path)[source]¶
Open a slide file using OpenSlide.
- Parameters:
path (Union[str, Path]) – Path to the slide file
- Raises:
FileNotFoundError – If the slide file does not exist
BackendError – If OpenSlide cannot open the file
- Return type:
None
- property num_levels: int¶
Get number of pyramid levels.
- Returns:
Number of pyramid levels
- Return type:
- get_thumbnail(size)[source]¶
Get thumbnail of the slide.
- property mpp: float¶
Get microns per pixel at base magnification.
- Returns:
Microns per pixel (MPP)
- Return type:
- Raises:
SlidePropertyError – If MPP cannot be determined from metadata
- class glasscut.slides.backends.CuCimBackend[source]¶
Bases:
SlideBackendCuCim-based backend for GPU-accelerated slide reading.
This backend uses RAPIDS cuCim for high-performance GPU-accelerated reading of whole slide images. Falls back to OpenSlide for metadata and operations not supported by cuCim.
- open(path)[source]¶
Open a slide file using CuCim.
- Parameters:
path (str | Path) – Path to the slide file
- Raises:
FileNotFoundError – If the slide file does not exist
BackendError – If cuCim cannot open the file
- Return type:
None
- property properties: dict[str, str]¶
Get slide metadata properties.
Falls back to OpenSlide for metadata retrieval.
- property num_levels: int¶
Get number of pyramid levels.
Falls back to OpenSlide for level information.
- Returns:
Number of pyramid levels
- Return type:
- read_region(location, level, size)[source]¶
Read a region/tile from the slide using GPU acceleration.
- get_thumbnail(size)[source]¶
Get thumbnail of the slide.
Falls back to OpenSlide if available.
- property mpp: float¶
Get microns per pixel at base magnification.
Falls back to OpenSlide for metadata retrieval.
- Returns:
Microns per pixel (MPP)
- Return type:
- Raises:
SlidePropertyError – If MPP cannot be determined from metadata