semantic_segmentor¶
Semantic Segmentation Engine for Whole Slide Images (WSIs) using TIAToolbox.
This module defines the SemanticSegmentor class, which extends the PatchPredictor engine to support semantic segmentation workflows on digital pathology images. It leverages deep learning models from TIAToolbox to perform patch-level and WSI-level inference, and includes utilities for preprocessing, postprocessing, and saving predictions in various formats.
Key Components:¶
Classes: - SemanticSegmentorRunParams:
Configuration parameters for controlling runtime behavior during segmentation.
- SemanticSegmentor:
Core engine for performing semantic segmentation on image patches or WSIs.
Functions: - concatenate_none:
Concatenate arrays while gracefully handling None values.
- merge_horizontal:
Incrementally merge horizontal patches and update location arrays.
- save_to_cache:
Save intermediate canvas and count arrays to Zarr cache.
- merge_vertical_chunkwise:
Merge vertically chunked canvas and count arrays into a probability map.
- store_probabilities:
Store computed probability data in Zarr or Dask arrays.
- prepare_full_batch:
Align patch-level predictions with global output locations.
Example: >>> from tiatoolbox.models.engine.semantic_segmentor import SemanticSegmentor >>> segmentor = SemanticSegmentor(model=”fcn_resnet50_unet-bcss”) >>> wsis = [“slide1.svs”, “slide2.svs”] >>> output = segmentor.run(wsis, patch_mode=False) >>> >>> patches = [np.ndarray, np.ndarray] >>> segmentor = SemanticSegmentor(model=”fcn_resnet50_unet-bcss”) >>> output = segmentor.run(patches, patch_mode=True, output_type=”dict”)
Notes:¶
Supports both patch-based and WSI-based segmentation.
Compatible with TIAToolbox pretrained models and custom PyTorch models.
Outputs can be saved as dictionaries, Zarr arrays, or AnnotationStore databases.
Includes memory-aware caching and efficient merging strategies for large-scale inference.
Functions
Clip probability chunk to target output shape and track written height. |
|
Concatenate arrays, handling None values gracefully. |
|
Return WSI output shape as (height, width) for the dataset if available. |
|
Merge patch-level predictions into a single canvas. |
|
Merge horizontal patches incrementally for each row of patches. |
|
Merge vertically chunked canvas and count arrays into a single probability map. |
|
Prepare full-sized output and count arrays for a batch of patch predictions. |
|
Incrementally save computed canvas and count arrays to Zarr cache. |
|
Store computed probability data into a Zarr dataset or accumulate in memory. |
Classes
Semantic segmentation engine for digital histology images. |
|
Runtime parameters for configuring the SemanticSegmentor.run() method. |