glasscut.slides package¶
Subpackages¶
Submodules¶
glasscut.slides.slide module¶
Main Slide class for WSI manipulation.
- class glasscut.slides.slide.Slide(path, use_cucim=True)[source]¶
Bases:
objectRepresents a whole slide image with magnification-based access.
This class provides an interface to access whole slide images. It abstracts away the backend (OpenSlide or cuCim).
- Parameters:
path (Union[str, pathlib.Path]) – Path to the slide file
use_cucim (bool, optional) – Whether to try using cuCim GPU backend. If False or cuCim is not available, falls back to OpenSlide. Default is True.
- __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
- property name: str¶
Slide name without extension.
- Returns:
Slide filename without extension
- Return type:
- property magnifications: list[float]¶
Available magnifications for this slide.
These are calculated from the actual slide’s base magnification (objective power) and the number of pyramid levels.
- property mpp: float¶
Microns per pixel at base magnification.
- Returns:
Microns per pixel
- Return type:
- Raises:
SlidelazypropertyError – If MPP cannot be determined from slide metadata
- property properties: dict[str, str]¶
Slide metadata properties.
- Returns:
Dictionary of all slide properties
- Return type:
- property thumbnail: Image¶
Get thumbnail of the slide.
The thumbnail size is automatically calculated based on slide dimensions.
- Returns:
Thumbnail image in RGB format
- Return type:
- extract_tile(coords, tile_size, magnification)[source]¶
Extract a single tile from the slide at specified magnification.
The requested magnification must be available on this slide. If the exact magnification is not available, a MagnificationError is raised.
- Parameters:
- Returns:
Extracted tile object
- Return type:
- Raises:
MagnificationError – If the requested magnification is not available on this slide
TileSizeOrCoordinatesError – If the coordinates or tile size are invalid
glasscut.slides.utils module¶
- glasscut.slides.utils.build_magnification_mapping(base_magnification, num_levels)[source]¶
Build a list of available magnifications from pyramid levels.
- glasscut.slides.utils.magnification_to_level(magnification, available_magnifications)[source]¶
Convert magnification to the pyramid level.
This function performs EXACT matching - the requested magnification must be available in the slide, otherwise an error is raised.
- Parameters:
- Returns:
The level index corresponding to the magnification
- Return type:
- Raises:
MagnificationError – If the requested magnification is not available on this slide
Module contents¶
Slide reading and manipulation module.
- class glasscut.slides.Slide(path, use_cucim=True)[source]¶
Bases:
objectRepresents a whole slide image with magnification-based access.
This class provides an interface to access whole slide images. It abstracts away the backend (OpenSlide or cuCim).
- Parameters:
path (Union[str, pathlib.Path]) – Path to the slide file
use_cucim (bool, optional) – Whether to try using cuCim GPU backend. If False or cuCim is not available, falls back to OpenSlide. Default is True.
- __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
- property name: str¶
Slide name without extension.
- Returns:
Slide filename without extension
- Return type:
- property magnifications: list[float]¶
Available magnifications for this slide.
These are calculated from the actual slide’s base magnification (objective power) and the number of pyramid levels.
- property mpp: float¶
Microns per pixel at base magnification.
- Returns:
Microns per pixel
- Return type:
- Raises:
SlidelazypropertyError – If MPP cannot be determined from slide metadata
- property properties: dict[str, str]¶
Slide metadata properties.
- Returns:
Dictionary of all slide properties
- Return type:
- property thumbnail: Image¶
Get thumbnail of the slide.
The thumbnail size is automatically calculated based on slide dimensions.
- Returns:
Thumbnail image in RGB format
- Return type:
- extract_tile(coords, tile_size, magnification)[source]¶
Extract a single tile from the slide at specified magnification.
The requested magnification must be available on this slide. If the exact magnification is not available, a MagnificationError is raised.
- Parameters:
- Returns:
Extracted tile object
- Return type:
- Raises:
MagnificationError – If the requested magnification is not available on this slide
TileSizeOrCoordinatesError – If the coordinates or tile size are invalid