Histolab
SkillDocs & knowledgeThis skill lets your AI extract and preprocess tiles from whole-slide images, the very large scanned images of tissue samples. Once added, your AI can load slide files with OpenSlide, find the tissue in them, cut them into smaller tiles, and apply filters so the tiles are ready for the next step in your work.
Available today. Use it from your connected AI after setup.
No other account needed.
After adding the skill, share a whole-slide image and tell your AI what you need, for example a grid of tiles from the tissue. It takes care of loading, tissue detection, and filtering from there.
Then ask your AI: use the Histolab skill
What your AI can do with it
- Load whole-slide image files for processing
- Detect tissue regions and build tissue masks
- Extract tiles at random or in an even grid
- Extract tiles by score instead of by fixed position
- Apply image and morphological filters to prepare H&E slides
What this skill tells your AI
The instructions your AI receives, as published by alterlab-ieu/alterlab-academic-skills in skills/bioinformatics/alterlab-histolab/SKILL.md and read by ahel’s review.
Overview
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.
When to Use This Skill
Use histolab for lightweight WSI tile pipelines: tissue detection, building tile datasets for ML training, H&E stain handling, and quick tile-based analysis of histopathology slides. For advanced spatial proteomics, multiplexed imaging, or full deep-learning pathology pipelines, use pathml instead.
Installation
uv pip install "histolab==0.7.0"
histolab wraps the OpenSlide C library, which is not bundled with the pip
package. On macOS install it with brew install openslide; without it, any
import histolab.slide fails with Couldn't locate OpenSlide dylib. The
examples below are pinned to histolab 0.7.0; the API differs in older releases.
Core Workflow
- Load the slide with
Slide(path, processed_path=...)and inspect dimensions/levels. - Detect tissue with a mask (
TissueMaskorBiggestTissueBoxMask). - Preview tile locations with
tiler.locate_tiles(slide)before committing. - Extract tiles with one of three tilers (Random/Grid/Score).
Minimal example:
from histolab.slide import Slide
from histolab.tiler import RandomTiler
slide = Slide("slide.svs", processed_path="output/")
# n_tiles, level, seed are CONSTRUCTOR args — not args to locate_tiles/extract.
tiler = RandomTiler(tile_size=(512, 512), n_tiles=100, level=0, seed=42)
tiler.locate_tiles(slide) # preview locations on the thumbnail first
tiler.extract(slide) # writes PNGs into processed_path
API gotcha (histolab 0.7.0): locate_tiles() and extract() take only
slide, an optional extraction_mask, and logging/styling kwargs — they do
not accept n_tiles. Set n_tiles (and seed, level, tile_size,
check_tissue, tissue_percent) on the tiler constructor. The
extraction_mask is passed to extract()/locate_tiles(), never to the
constructor.
Full copy-pasteable pipelines (quick start, 5 end-to-end workflows, and per-capability examples) live in references/workflows.md.
Core Capabilities
1. Slide Management
Load, inspect, and work with WSI files (SVS, TIFF, NDPI, etc.): access metadata
(dimensions, magnification, properties), generate thumbnails, and work with
pyramidal/multi-level structures. Key class: Slide.
See references/slide_management.md for slide initialization, built-in sample
datasets (prostate_tissue, ovarian_tissue, breast_tissue, heart_tissue,
aorta_tissue, plus pen-marked and IHC samples), pyramid levels, and
multi-slide processing.
2. Tissue Detection and Masks
Automatically identify tissue regions and filter background/artifacts. Key
classes: TissueMask (all tissue regions), BiggestTissueBoxMask (bounding box
of largest region — the default), and BinaryMask (base class for custom masks).
Choosing a mask:
TissueMask: multiple tissue sections, comprehensive analysisBiggestTissueBoxMask: single main section, exclude artifacts (default)- Custom
BinaryMask: specific ROI, exclude annotations, custom segmentation
See references/tissue_masks.md for how detection filters work, visualizing
masks with locate_mask(), and custom rectangular / annotation-exclusion masks.
3. Tile Extraction
Extract smaller regions from large WSI using one of three strategies:
- RandomTiler — fixed number of randomly positioned tiles. Best for sampling
diverse regions, exploration, training data. Key params:
n_tiles,seed. - GridTiler — systematic grid across tissue. Best for complete coverage,
spatial analysis, reconstruction. Key param:
pixel_overlap. - ScoreTiler — top-ranked tiles by scoring function. Best for informative
regions, quality-driven selection. Key param:
scorer(NucleiScorer, CellularityScorer, custom).
Common parameters: tile_size, level (0 = highest res), check_tissue,
tissue_percent (default 80%), extraction_mask. Always preview with
locate_tiles() before extracting.
See references/tile_extraction.md for scorers, reporting, and advanced
(multi-level, hierarchical) extraction patterns.
4. Filters and Preprocessing
Apply image-processing filters for tissue detection, QC, and preprocessing:
- Image filters —
RgbToGrayscale,RgbToHsv,RgbToHed,OtsuThreshold,Invert,StretchContrast,HistogramEqualization,Lambda. - Morphological filters —
BinaryDilation,BinaryErosion,BinaryOpening,BinaryClosing,RemoveSmallObjects,RemoveSmallHoles. - Composition —
Compose(inhistolab.filters.image_filters) chains filters into pipelines. Pass custom filters to a mask as positional varargs:TissueMask(RgbToGrayscale(), OtsuThreshold(), ...).
See references/filters_preprocessing.md for filter chaining, common pipelines
(tissue detection, pen removal, nuclei enhancement), and QC filters.
5. Visualization
Display slides, masks, tile locations, and extraction quality: thumbnails, mask
overlays via locate_mask(), tile-location previews via locate_tiles(), tile
mosaics, and score distributions.
See references/visualization.md for mosaics, quality-assessment plots,
multi-slide comparison, and exporting high-resolution figures / PDF reports.
Reference Index
references/workflows.md— quick start, per-capability examples, and 5 end-to-end worked workflows (exploratory, grid, score-driven, multi-slide, custom tissue detection).references/slide_management.md— loading/inspecting slides, sample datasets, pyramid levels, multi-slide processing.references/tissue_masks.md—TissueMask/BiggestTissueBoxMask/BinaryMask, custom masks, mask visualization and integration.references/tile_extraction.md— Random/Grid/Score tiler comparison, scorers, CSV reporting, advanced extraction patterns.references/filters_preprocessing.md— image + morphological filters, filter composition, preprocessing pipelines, QC filters.references/visualization.md— thumbnails, mask/tile previews, mosaics, quality plots, figure export.references/best_practices.md— best practices, common use cases, and troubleshooting (no tiles, background tiles, slow extraction, artifacts).
Load the specific reference file you need for detailed implementation guidance, troubleshooting, or advanced features.
Signals
- GitHub stars
- 66
- Forks
- 13
- Last commit
- Sep 2026
Advanced
- Catalog kind
- skill
- Gateway key
alterlab-histolab- Source
- github.com/alterlab-ieu/alterlab-academic-skills