2
1
Source

Lightweight WSI tile extraction and preprocessing. Use for basic slide processing tissue detection, tile extraction, stain normalization for H&E images. Best for simple pipelines, dataset preparation, quick tile-based analysis. For advanced spatial proteomics, multiplexed imaging, or deep learning pipelines use pathml.

Install

mkdir -p .claude/skills/histolab && curl -L -o skill.zip "https://mcp.directory/api/skills/download/5224" && unzip -o skill.zip -d .claude/skills/histolab && rm skill.zip

Installs to .claude/skills/histolab

About this skill

Histolab

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.

Installation

uv pip install histolab

Quick Start

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)

Core Capabilities

1. Slide Management

Load, inspect, and work with whole slide images in various formats.

Common operations:

  • Loading WSI files (SVS, TIFF, NDPI, etc.)
  • Accessing slide metadata (dimensions, magnification, properties)
  • Generating thumbnails for visualization
  • Working with pyramidal image structures
  • Extracting regions at specific coordinates

Key classes: Slide

Reference: references/slide_management.md contains comprehensive documentation on:

  • Slide initialization and configuration
  • Built-in sample datasets (prostate, ovarian, breast, heart, kidney tissues)
  • Accessing slide properties and metadata
  • Thumbnail generation and visualization
  • Working with pyramid levels
  • Multi-slide processing workflows

Example workflow:

from 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()

2. Tissue Detection and Masks

Automatically identify tissue regions and filter background/artifacts.

Common operations:

  • Creating binary tissue masks
  • Detecting largest tissue region
  • Excluding background and artifacts
  • Custom tissue segmentation
  • Removing pen annotations

Key classes: TissueMask, BiggestTissueBoxMask, BinaryMask

Reference: references/tissue_masks.md contains comprehensive documentation on:

  • TissueMask: Segments all tissue regions using automated filters
  • BiggestTissueBoxMask: Returns bounding box of largest tissue region (default)
  • BinaryMask: Base class for custom mask implementations
  • Visualizing masks with locate_mask()
  • Creating custom rectangular and annotation-exclusion masks
  • Mask integration with tile extraction
  • Best practices and troubleshooting

Example workflow:

from 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 analysis
  • BiggestTissueBoxMask: Single main tissue section, exclude artifacts (default)
  • Custom BinaryMask: Specific ROI, exclude annotations, custom segmentation

3. Tile Extraction

Extract smaller regions from large WSI using different strategies.

Three extraction strategies:

RandomTiler: Extract fixed number of randomly positioned tiles

  • Best for: Sampling diverse regions, exploratory analysis, training data
  • Key parameters: n_tiles, seed for reproducibility

GridTiler: Systematically extract tiles across tissue in grid pattern

  • Best for: Complete coverage, spatial analysis, reconstruction
  • Key parameters: pixel_overlap for sliding windows

ScoreTiler: Extract top-ranked tiles based on scoring functions

  • Best for: Most informative regions, quality-driven selection
  • Key parameters: 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 content
  • tissue_percent: Minimum tissue coverage (default 80%)
  • extraction_mask: Mask defining extraction region

Reference: references/tile_extraction.md contains comprehensive documentation on:

  • Detailed explanation of each tiler strategy
  • Available scorers (NucleiScorer, CellularityScorer, custom)
  • Tile preview with locate_tiles()
  • Extraction workflows and reporting
  • Advanced patterns (multi-level, hierarchical extraction)
  • Performance optimization and troubleshooting

Example workflows:

from 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:

# Preview tile locations on thumbnail
tiler.locate_tiles(slide, n_tiles=20)

4. Filters and Preprocessing

Apply image processing filters for tissue detection, quality control, and preprocessing.

Filter categories:

Image Filters: Color space conversions, thresholding, contrast enhancement

  • RgbToGrayscale, RgbToHsv, RgbToHed
  • OtsuThreshold, AdaptiveThreshold
  • StretchContrast, HistogramEqualization

Morphological Filters: Structural operations on binary images

  • BinaryDilation, BinaryErosion
  • BinaryOpening, BinaryClosing
  • RemoveSmallObjects, RemoveSmallHoles

Composition: Chain multiple filters together

  • Compose: Create filter pipelines

Reference: references/filters_preprocessing.md contains comprehensive documentation on:

  • Detailed explanation of each filter type
  • Filter composition and chaining
  • Common preprocessing pipelines (tissue detection, pen removal, nuclei enhancement)
  • Applying filters to tiles
  • Custom mask filters
  • Quality control filters (blur detection, tissue coverage)
  • Best practices and troubleshooting

Example workflows:

from 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)

5. Visualization

Visualize slides, masks, tile locations, and extraction quality.

Common visualization tasks:

  • Displaying slide thumbnails
  • Visualizing tissue masks
  • Previewing tile locations
  • Assessing tile quality
  • Creating reports and figures

Reference: references/visualization.md contains comprehensive documentation on:

  • Slide thumbnail display and saving
  • Mask visualization with locate_mask()
  • Tile location preview with locate_tiles()
  • Displaying extracted tiles and mosaics
  • Quality assessment (score distributions, top vs bottom tiles)
  • Multi-slide visualization
  • Filter effect visualization
  • Exporting high-resolution figures and PDF reports
  • Interactive visualization in Jupyter notebooks

Example workflows:

import 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()

Typical Workflows

Workflow 1: Exploratory Tile Extraction

Quick sampling of diverse tissue regions for initial analysis.

from 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)


Content truncated.

literature-review

K-Dense-AI

Conduct comprehensive, systematic literature reviews using multiple academic databases (PubMed, arXiv, bioRxiv, Semantic Scholar, etc.). This skill should be used when conducting systematic literature reviews, meta-analyses, research synthesis, or comprehensive literature searches across biomedical, scientific, and technical domains. Creates professionally formatted markdown documents and PDFs with verified citations in multiple citation styles (APA, Nature, Vancouver, etc.).

978420

markitdown

K-Dense-AI

Convert various file formats (PDF, Office documents, images, audio, web content, structured data) to Markdown optimized for LLM processing. Use when converting documents to markdown, extracting text from PDFs/Office files, transcribing audio, performing OCR on images, extracting YouTube transcripts, or processing batches of files. Supports 20+ formats including DOCX, XLSX, PPTX, PDF, HTML, EPUB, CSV, JSON, images with OCR, and audio with transcription.

224108

scientific-writing

K-Dense-AI

Write scientific manuscripts. IMRAD structure, citations (APA/AMA/Vancouver), figures/tables, reporting guidelines (CONSORT/STROBE/PRISMA), abstracts, for research papers and journal submissions.

26978

pubmed-database

K-Dense-AI

"Direct REST API access to PubMed. Advanced Boolean/MeSH queries, E-utilities API, batch processing, citation management. For Python workflows, prefer biopython (Bio.Entrez). Use this for direct HTTP/REST work or custom API implementations."

14945

reportlab

K-Dense-AI

"PDF generation toolkit. Create invoices, reports, certificates, forms, charts, tables, barcodes, QR codes, Canvas/Platypus APIs, for professional document automation."

15028

matplotlib

K-Dense-AI

Foundational plotting library. Create line plots, scatter, bar, histograms, heatmaps, 3D, subplots, export PNG/PDF/SVG, for scientific visualization and publication figures.

13024

You might also like

flutter-development

aj-geddes

Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.

1,6871,430

ui-ux-pro-max

nextlevelbuilder

"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."

1,2711,336

drawio-diagrams-enhanced

jgtolentino

Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.

1,5451,153

godot

bfollington

This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.

1,359809

nano-banana-pro

garg-aayush

Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.

1,266730

pdf-to-markdown

aliceisjustplaying

Convert entire PDF documents to clean, structured Markdown for full context loading. Use this skill when the user wants to extract ALL text from a PDF into context (not grep/search), when discussing or analyzing PDF content in full, when the user mentions "load the whole PDF", "bring the PDF into context", "read the entire PDF", or when partial extraction/grepping would miss important context. This is the preferred method for PDF text extraction over page-by-page or grep approaches.

1,495685