mahmoodlab/TRIDENT
Toolkit for large-scale whole-slide image processing.
What is Trident?
Trident is an open-source toolkit designed to process whole-slide images (WSIs) — the high-resolution digital scans of tissue samples used in pathology. It automates the common steps needed to turn raw slide images into machine-readable features for AI models.
Developed by the Mahmood Lab at Harvard Medical School and Brigham and Women's Hospital, Trident provides an end-to-end pipeline that can handle thousands of slides efficiently.
Key Features
- End-to-end pipeline: Run tissue segmentation, patch extraction, and feature extraction in one command (
--task all) or step-by-step. - 34 patch encoders: Pre-trained models that convert small image patches into numerical vectors (e.g., UNI, CONCH, Virchow).
- 12 slide encoders: Models that summarize an entire slide into a single embedding (e.g., Titan, PRISM, CHIEF).
- Multiple tissue segmentation methods: HEST (default), GrandQC, or Otsu (CPU-only). Optional artifact/penmark removal.
- Flexible file format support: Reads OpenSlide, CuCIM, plain images, OME-Zarr, Zeiss CZI, Philips iSyntax, and more. Can convert to pyramidal TIFF.
- Multi-GPU support: Distribute slides across multiple GPUs with
--gpus 0 1 2 3. - Smart resume: Re-running on the same output directory skips already-completed slides; lock files prevent conflicts.
- WSI caching: For slow/network storage, cache slides locally to speed up processing.
- Run reports: Every run generates human-readable summaries and per-slide status files.
How It Works
Trident processes slides in three main stages:
- Tissue Segmentation – Identifies tissue regions and separates them from background.
- Patching – Cuts the tissue into small square patches at a specified magnification and size.
- Feature Extraction – Uses a patch encoder (to get per-patch features) or a slide encoder (to get a whole-slide embedding).
You can run all stages at once or step-by-step, and each stage produces intermediate outputs that can be reused.
Installation
Requires Python 3.10 or 3.11. Basic install:
conda create -n trident python=3.10
conda activate trident
git clone https://github.com/mahmoodlab/trident.git
cd trident
pip install -e .
Optional extras for specific models or file formats:
pip install -e ".[patch-encoders]"– for additional patch encoders (e.g., CONCH, MUSK)pip install -e ".[slide-encoders]"– for additional slide encoders (e.g., PRISM, GigaPath)pip install -e ".[omezarr]"– for OME-Zarr supportpip install -e ".[czi]"– for Zeiss CZI supportpip install -e ".[isyntax]"– for Philips iSyntax supportpip install -e ".[convert]"– for slide conversion to TIFFpip install -e ".[full]"– installs all optional dependencies
Run trident-doctor to verify your setup.
Usage Examples
Run everything (segmentation + patching + UNI features) on a folder of slides:
python run_batch_of_slides.py --task all --wsi_dir ./wsis --job_dir ./trident_processed --patch_encoder uni_v1 --mag 20 --patch_size 256
Process a single slide:
python run_single_slide.py --slide_path ./wsis/xxxx.svs --job_dir ./trident_processed --patch_encoder uni_v1 --mag 20 --patch_size 256
Step-by-step:
- Segmentation:
python run_batch_of_slides.py --task seg --wsi_dir ./wsis --job_dir ./trident_processed --gpus 0 --segmenter hest - Patching:
python run_batch_of_slides.py --task coords --wsi_dir ./wsis --job_dir ./trident_processed --mag 20 --patch_size 256 --overlap 0 - Patch features:
python run_batch_of_slides.py --task feat --wsi_dir ./wsis --job_dir ./trident_processed --patch_encoder uni_v1 --mag 20 --patch_size 256 - Slide features:
python run_batch_of_slides.py --task feat --wsi_dir ./wsis --job_dir ./trident_processed --slide_encoder titan --mag 20 --patch_size 512
Supported Models
Trident supports a wide range of pre-trained models. Each model has specific requirements (e.g., patch size, magnification, license). Some models require manual setup (e.g., local paths) or HuggingFace gated access.
Patch encoders (34 total) include: UNI, CONCH, Virchow, Prov-GigaPath, H-Optimus-0, Phikon, and many more.
Slide encoders (12 total) include: Titan, PRISM, CHIEF, GigaPath, Madeleine, and others.
Refer to the README tables for full lists, arguments, and licenses.
Outputs
- Segmentation: Thumbnails, contour overlays, and GeoJSON files (editable in QuPath).
- Patching: Patch coordinates (H5 files) and annotated thumbnails.
- Patch features: H5 files with shape
(n_patches, feature_dim). - Slide features: H5 files with shape
(feature_dim). - Run reports:
summary.md, JSON manifests, and per-slide status files.
Notes
- Some models are gated on HuggingFace; you must request access.
- Some models require specific installations (e.g.,
transformers>=5for Gemma 4, which conflicts withhibou_l– use separate environments). - The
--mpp_csvoption is required for slide conversion and must containwsi,mppcolumns. - Trident includes an Agent Skill for AI coding assistants (e.g., Claude Code) to drive the pipeline automatically.
For full details, see the official documentation.
Related
- Project
- Project
- Project
- Project
- Project