Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Digital pathology image processing toolkit for whole slide images (WSI). Use this skill when working with histopathology slides, processing H&E or IHC stained tissue images, extracting tiles from gigapixel pathology images, detecting tissue regions, segmenting tissue masks, or preparing datasets for computational pathology deep learning pipelines. Applies to WSI formats (SVS, TIFF, NDPI), tile-based analysis, and histological image preprocessing workflows.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-13 | ✗→✓ | ▲ Improved | — | — |
| case-02 | ✗→✓ | ▲ Improved | — | — |
| case-12 | ✗→✓ | ▲ Improved | — | — |
| case-01 | ✗→✓ | ▲ Improved | — | — |
| case-04 | ✗→✓ | ▲ Improved | — | — |
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.
bashuv pip install histolab
Basic workflow for extracting tiles from a whole slide image:
pythonfrom 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)
Load, inspect, and work with whole slide images in various formats.
Common operations:
Key classes: Slide
Reference: references/slide_management.md contains comprehensive documentation on:
Example workflow:
pythonfrom histolab.slide import Slide from histolab.data import prostate_tissue # Load sample data prostate_svs, prostate_path = prostate_tissue() # Initialize slide slide = Slide(prostate_path, processed_path="output/") # Inspect properties print(f"Dimensions: {slide.dimensions}") print(f"Levels: {slide.levels}") print(f"Magnification: {slide.properties.get('openslide.objective-power')}") # Save thumbnail slide.save_thumbnail()
Automatically identify tissue regions and filter background/artifacts.
Common operations:
Key classes: TissueMask, BiggestTissueBoxMask, BinaryMask
Reference: references/tissue_masks.md contains comprehensive documentation on:
locate_mask()Example workflow:
pythonfrom histolab.masks import TissueMask, BiggestTissueBoxMask # Create tissue mask for all tissue regions tissue_mask = TissueMask() # Visualize mask on slide slide.locate_mask(tissue_mask) # Get mask array mask_array = tissue_mask(slide) # Use largest tissue region (default for most extractors) biggest_mask = BiggestTissueBoxMask()
When to use each mask:
TissueMask: Multiple tissue sections, comprehensive analysisBiggestTissueBoxMask: Single main tissue section, exclude artifacts (default)BinaryMask: Specific ROI, exclude annotations, custom segmentationExtract smaller regions from large WSI using different strategies.
Three extraction strategies:
RandomTiler: Extract fixed number of randomly positioned tiles
n_tiles, seed for reproducibilityGridTiler: Systematically extract tiles across tissue in grid pattern
pixel_overlap for sliding windowsScoreTiler: Extract top-ranked tiles based on scoring functions
scorer (NucleiScorer, CellularityScorer, custom)Common parameters:
tile_size: Tile dimensions (e.g., (512, 512))level: Pyramid level for extraction (0 = highest resolution)check_tissue: Filter tiles by tissue contenttissue_percent: Minimum tissue coverage (default 80%)extraction_mask: Mask defining extraction regionReference: references/tile_extraction.md contains comprehensive documentation on:
locate_tiles()Example workflows:
pythonfrom histolab.tiler import RandomTiler, GridTiler, ScoreTiler from histolab.scorer import NucleiScorer # Random sampling (fast, diverse) random_tiler = RandomTiler( tile_size=(512, 512), n_tiles=100, level=0, seed=42, check_tissue=True, tissue_percent=80.0 ) random_tiler.extract(slide) # Grid coverage (comprehensive) grid_tiler = GridTiler( tile_size=(512, 512), level=0, pixel_overlap=0, check_tissue=True ) grid_tiler.extract(slide) # Score-based selection (most informative) score_tiler = ScoreTiler( tile_size=(512, 512), n_tiles=50, scorer=NucleiScorer(), level=0 ) score_tiler.extract(slide, report_path="tiles_report.csv")
Always preview before extracting:
python# Preview tile locations on thumbnail tiler.locate_tiles(slide, n_tiles=20)
Apply image processing filters for tissue detection, quality control, and preprocessing.
Filter categories:
Image Filters: Color space conversions, thresholding, contrast enhancement
RgbToGrayscale, RgbToHsv, RgbToHedOtsuThreshold, AdaptiveThresholdStretchContrast, HistogramEqualizationMorphological Filters: Structural operations on binary images
BinaryDilation, BinaryErosionBinaryOpening, BinaryClosingRemoveSmallObjects, RemoveSmallHolesComposition: Chain multiple filters together
Compose: Create filter pipelinesReference: references/filters_preprocessing.md contains comprehensive documentation on:
Example workflows:
pythonfrom histolab.filters.compositions import Compose from histolab.filters.image_filters import RgbToGrayscale, OtsuThreshold from histolab.filters.morphological_filters import ( BinaryDilation, RemoveSmallHoles, RemoveSmallObjects ) # Standard tissue detection pipeline tissue_detection = Compose([ RgbToGrayscale(), OtsuThreshold(), BinaryDilation(disk_size=5), RemoveSmallHoles(area_threshold=1000), RemoveSmallObjects(area_threshold=500) ]) # Use with custom mask from histolab.masks import TissueMask custom_mask = TissueMask(filters=tissue_detection) # Apply filters to tile from histolab.tile import Tile filtered_tile = tile.apply_filters(tissue_detection)
Visualize slides, masks, tile locations, and extraction quality.
Common visualization tasks:
Reference: references/visualization.md contains comprehensive documentation on:
locate_mask()locate_tiles()Example workflows:
pythonimport matplotlib.pyplot as plt from histolab.masks import TissueMask # Display slide thumbnail plt.figure(figsize=(10, 10)) plt.imshow(slide.thumbnail) plt.title(f"Slide: {slide.name}") plt.axis('off') plt.show() # Visualize tissue mask tissue_mask = TissueMask() slide.locate_mask(tissue_mask) # Preview tile locations tiler = RandomTiler(tile_size=(512, 512), n_tiles=50) tiler.locate_tiles(slide, n_tiles=20) # Display extracted tiles in grid from pathlib import Path from PIL import Image tile_paths = list(Path("output/tiles/").glob("*.png"))[:16] fig, axes = plt.subplots(4, 4, figsize=(12, 12)) axes = axes.ravel() for idx, tile_path in enumerate(tile_paths): tile_img = Image.open(tile_path) axes[idx].imshow(tile_img) axes[idx].set_title(tile_path.stem, fontsize=8) axes[idx].axis('off') plt.tight_layout() plt.show()
Quick sampling of diverse tissue regions for initial analysis.
pythonfrom histolab.slide import Slide from histolab.tiler import RandomTiler import logging # Enable logging for progress tracking logging.basicConfig(level=logging.INFO) # Load slide slide = Slide("slide.svs", processed_path="output/random_tiles/") # Inspect slide print(f"Dimensions: {slide.dimensions}") print(f"Levels: {slide.levels}") slide.save_thumbnail() # Configure random tiler random_tiler = RandomTiler( tile_size=(512, 512), n_tiles=100, level=0, seed=42, check_tissue=True, tissue_percent=80.0 ) # Preview locations random_tiler.locate_tiles(slide, n_tiles=20) # Extract tiles random_tiler.extract(slide)
Complete tissue coverage for whole-slide analysis.
pythonfrom histolab.slide import Slide from histolab.tiler import GridTiler from histolab.masks import TissueMask # Load slide slide = Slide("slide.svs", processed_path="output/grid_tiles/") # Use TissueMask for all tissue sections tissue_mask = TissueMask() slide.locate_mask(tissue_mask) # Configure grid tiler grid_tiler = GridTiler( tile_size=(512, 512), level=1, # Use level 1 for faster extraction pixel_overlap=0, check_tissue=True, tissue_percent=70.0 ) # Preview grid grid_tiler.locate_tiles(slide) # Extract all tiles grid_tiler.extract(slide, extraction_mask=tissue_mask)
Extract most informative tiles based on nuclei density.
pythonfrom histolab.slide import Slide from histolab.tiler import ScoreTiler from histolab.scorer import NucleiScorer import pandas as pd import matplotlib.pyplot as plt # Load slide slide = Slide("slide.svs", processed_path="output/scored_tiles/") # Configure score tiler score_tiler = ScoreTiler( tile_size=(512, 512), n_tiles=50, level=0, scorer=NucleiScorer(), check_tissue=True ) # Preview top tiles score_tiler.locate_tiles(slide, n_tiles=15) # Extract with report score_tiler.extract(slide, report_path="tiles_report.csv") # Analyze scores report_df = pd.read_csv("tiles_report.csv") plt.hist(report_df['score'], bins=20, edgecolor='black') plt.xlabel('Tile Score') plt.ylabel('Frequency') plt.title('Distribution of Tile Scores') plt.show()
Process entire slide collection with consistent parameters.
pythonfrom pathlib import Path from histolab.slide import Slide from histolab.tiler import RandomTiler import logging logging.basicConfig(level=logging.INFO) # Configure tiler once tiler = RandomTiler( tile_size=(512, 512), n_tiles=50, level=0, seed=42, check_tissue=True ) # Process all slides slide_dir = Path("slides/") output_base = Path("output/") for slide_path in slide_dir.glob("*.svs"): print(f"\nProcessing: {slide_path.name}") # Create slide-specific output directory output_dir = output_base / slide_path.stem output_dir.mkdir(parents=True, exist_ok=True) # Load and process slide slide = Slide(slide_path, processed_path=output_dir) # Save thumbnail for review slide.save_thumbnail() # Extract tiles tiler.extract(slide) print(f"Completed: {slide_path.name}")
Handle slides with artifacts, annotations, or unusual staining.
pythonfrom histolab.slide import Slide from histolab.masks import TissueMask from histolab.tiler import RandomTiler from histolab.filters.compositions import Compose from histolab.filters.image_filters import RgbToGrayscale, OtsuThreshold from histolab.filters.morphological_filters import ( BinaryDilation, RemoveSmallObjects, RemoveSmallHoles ) # Define custom filter pipeline for aggressive artifact removal aggressive_filters = Compose([ RgbToGrayscale(), OtsuThreshold(), BinaryDilation(disk_size=10), RemoveSmallHoles(area_threshold=5000), RemoveSmallObjects(area_threshold=3000) # Remove larger artifacts ]) # Create custom mask custom_mask = TissueMask(filters=aggressive_filters) # Load slide and visualize mask slide = Slide("slide.svs", processed_path="output/") slide.locate_mask(custom_mask) # Extract with custom mask tiler = RandomTiler(tile_size=(512, 512), n_tiles=100) tiler.extract(slide, extraction_mask=custom_mask)
locate_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/ScoreTilertissue_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.
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-13 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-23 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-02 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-20 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-19 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-18 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-10 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-17 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-12 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-07 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-05 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-15 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-01 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-21 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-14 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-04 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-03 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-06 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-08 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-09 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-11 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-16 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-22 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 23 cases were attempted. The headline lift of +26 percentage points is the difference between those two pass rates over the 23 comparable cases.
The per-case answers from this run were removed by the retention sweep, so the case table below shows the verdicts without the text either arm produced. The counts above were recorded at the time and are unaffected. Answers are now kept for 180 days.
Other measured skills in the registry, with their headline benchmark lift.