Lightweight WSI tile extraction and preprocessing. Use for basic slide processing, tissue detection, tile extraction, and stain normalization for H&E images. Best for simple pipelines, dataset preparation, and quick tile-based analysis. For advanced spatial proteomics, multiplexed imaging, or deep learning pipelines use pathml.
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.
Copy a source-pinned command for your client. You run it yourself.
Destination: .claude/skills/histolab · pinned to the source commit
git clone https://github.com/K-Dense-AI/scientific-agent-skills.git
cd scientific-agent-skills
git checkout 36d8f13a1e754618794bf42f417884940077b4ae
mkdir -p ".claude/skills/histolab"
cp -r "skills/histolab" ".claude/skills/histolab"Review the source before running. This copies files into your project; it is not a one-click install and does not verify runtime safety.
sudo apt update && sudo apt install -y gitnpm install -g @anthropic-ai/claude-codegit clone https://github.com/K-Dense-AI/scientific-agent-skills.git
cd scientific-agent-skills
git checkout 36d8f13a1e754618794bf42f417884940077b4ae
mkdir -p ".claude/skills/histolab"
cp -r "skills/histolab" ".claude/skills/histolab"Destination: .claude/skills/histolab
Scanner static-checks@0.1.0 · commit 36d8f13a1e75. Static checks cannot prove runtime safety – review the source and the exact diff before installing. How checks work.
Instructs shell/process/package operations that run commands on the host.
Evidence: pip install· fingerprint 7944ec554efca445