Slide Module
slide.py: Contains the Slide and Annotations classes.
Slide class: Wrapper around openslide.OpenSlide with annotation overlay and mask generation. Annotations class: Parses annotation files from QuPath, ImageJ, and ASAP.
- class pyslyde.slide.Slide(filename, mag=0, annotations=None, annotations_path=None, labels=None, source=None)[source]
Bases:
OpenSlide
Whole Slide Image (WSI) object that enables annotation overlay as a wrapper around openslide.OpenSlide. Generates annotation mask.
- __init__(filename, mag=0, annotations=None, annotations_path=None, labels=None, source=None)[source]
Open a whole-slide image.
- static resize_border(dim, factor=1, threshold=None, operator='=>')[source]
Resize and redraw annotation border. Useful to trim WSI and mask to a specific size.
- detect_components(level_dims=6, num_component=None, min_size=None)[source]
Find the largest section on the slide.
- generate_region(mag=0, x=None, y=None, x_size=None, y_size=None, scale_border=False, factor=1, threshold=None, operator='=>')[source]
Extract a specific region of the slide.
- Parameters:
mag (int) – Magnification level.
x (int or tuple, optional) – Minimum x coordinate or (x_min, x_max).
y (int or tuple, optional) – Minimum y coordinate or (y_min, y_max).
x_size (int, optional) – Width of the region.
y_size (int, optional) – Height of the region.
scale_border (bool) – Whether to resize the border.
factor (int) – Factor for resizing.
threshold (int, optional) – Threshold for resizing.
operator (str) – Operator for threshold.
- Returns:
(Extracted region as RGB ndarray, mask)
- Return type:
- class pyslyde.slide.Annotations(path, source, labels=None, encode=False)[source]
Bases:
object
Parses annotation files in XML or JSON format and returns a dictionary containing x, y coordinates for each region of interest (ROI).
- Parameters:
- rename_labels(names)[source]
Rename annotation labels.
- Parameters:
names (dict) – Mapping from current labels to new labels.
- encode_keys()[source]
Encode labels as integer values.
- Returns:
Annotations with integer keys.
- Return type:
Slide Class
- class pyslyde.slide.Slide(filename, mag=0, annotations=None, annotations_path=None, labels=None, source=None)[source]
Bases:
OpenSlide
Whole Slide Image (WSI) object that enables annotation overlay as a wrapper around openslide.OpenSlide. Generates annotation mask.
- __init__(filename, mag=0, annotations=None, annotations_path=None, labels=None, source=None)[source]
Open a whole-slide image.
- static resize_border(dim, factor=1, threshold=None, operator='=>')[source]
Resize and redraw annotation border. Useful to trim WSI and mask to a specific size.
- detect_components(level_dims=6, num_component=None, min_size=None)[source]
Find the largest section on the slide.
- generate_region(mag=0, x=None, y=None, x_size=None, y_size=None, scale_border=False, factor=1, threshold=None, operator='=>')[source]
Extract a specific region of the slide.
- Parameters:
mag (int) – Magnification level.
x (int or tuple, optional) – Minimum x coordinate or (x_min, x_max).
y (int or tuple, optional) – Minimum y coordinate or (y_min, y_max).
x_size (int, optional) – Width of the region.
y_size (int, optional) – Height of the region.
scale_border (bool) – Whether to resize the border.
factor (int) – Factor for resizing.
threshold (int, optional) – Threshold for resizing.
operator (str) – Operator for threshold.
- Returns:
(Extracted region as RGB ndarray, mask)
- Return type:
Annotations Class
- class pyslyde.slide.Annotations(path, source, labels=None, encode=False)[source]
Bases:
object
Parses annotation files in XML or JSON format and returns a dictionary containing x, y coordinates for each region of interest (ROI).
- Parameters:
- rename_labels(names)[source]
Rename annotation labels.
- Parameters:
names (dict) – Mapping from current labels to new labels.
- encode_keys()[source]
Encode labels as integer values.
- Returns:
Annotations with integer keys.
- Return type: