skills/histolab/SKILL.md
Histolab is a Python library for processing whole slide images (WSI) in digital pathology. It automates tissue detection, extracts informative tiles from gigapixel images, and prepares datasets for deep learning pipelines. The library handles multiple WSI formats, implements sophisticated tissue segmentation, and provides flexible tile extraction strategies.
Install OpenSlide system libraries first (OpenSlide download), then install histolab:
uv pip install histolab
For built-in TCGA sample slides via histolab.data, also install pooch:
uv pip install pooch
Histolab 0.7.0 (latest stable) supports Python 3.8–3.11 on Linux and macOS. Windows is not supported as of 0.7.0.
Basic workflow for extracting tiles from a whole slide image:
from histolab.slide import Slide
from histolab.tiler import RandomTiler
# Load slide
slide = Slide("slide.svs", processed_path="output/")
# Configure tiler
tiler = RandomTiler(
tile_size=(512, 512),
n_tiles=100,
level=0,
seed=42
)
# Preview tile locations
tiler.locate_tiles(slide, n_tiles=20)
# Extract tiles
tiler.extract(slide)
Six capability areas, each with worked code, are documented in references/core_capabilities.md:
TissueMask and BiggestTissueBoxMask, and custom masks.Five end-to-end workflows are in references/typical_workflows.md. Per-topic detail lives in references/slide_management.md, references/tissue_masks.md, references/tile_extraction.md, references/filters_preprocessing.md, and references/visualization.md.
slide.thumbnail.save() for quick visual reviewlocate_mask() before extractionTissueMask for multiple sections, BiggestTissueBoxMask for single sectionslocate_tiles() before extractingtissue_percent threshold (70-90% typical)BiggestTissueBoxMask over TissueMask when appropriatetissue_percent to reduce invalid tile attemptsn_tiles for initial explorationpixel_overlap=0 for non-overlapping gridspixel_overlap for sliding window approachestissue_percent thresholdcheck_tissue=Truetissue_percent thresholdn_tiles for RandomTiler/ScoreTilerMacenkoStainNormalizer or ReinhardStainNormalizertissue_percent per staining qualityThis skill includes detailed reference documentation in the references/ directory:
Comprehensive guide to loading, inspecting, and working with whole slide images:
Complete documentation on tissue detection and masking:
Detailed explanation of tile extraction strategies:
Complete filter reference and preprocessing guide:
Comprehensive visualization guide:
Usage pattern: Reference files contain in-depth information to support workflows described in this main skill document. Load specific reference files as needed for detailed implementation guidance, troubleshooting, or advanced features.