### Histolab
Works with
name: "histolab"
description: "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 prepara..."
AI-first code editor with Composer
Before installing skills in Cursor, ensure your development environment meets these requirements:
node --versionhistolabExecute the skills CLI command in your project's root directory to begin installation:
Fetches histolab from K-Dense-AI/scientific-agent-skills and configures it for Cursor.
The CLI shows a list of agents. Use arrow keys and space to select Cursor:
Confirm successful installation by checking the skill directory location:
Restart Cursor to activate histolab. Access via /histolab in your agent's command palette.
We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.
Skills execute code in your environment. Always review source, verify the publisher, and test in isolation before production.
Submit your Claude Code skill and start earning
Automate repetitive workflows and reduce manual effort
Example
Generate reports, summarize documents, draft communications
Save 3-5 hours per week on routine tasks
Learn new skills, understand complex topics, get expert guidance
Example
Explain concepts, provide examples, suggest learning resources
Accelerate learning and skill development by 2x
Enhance output quality through reviews, suggestions, and refinements
Example
Review drafts, suggest improvements, catch errors
Improve work quality by 30-40% with less effort
0
total installs
0
this week
0
upvotes
Run in your terminal
0
installs
0
this week
—
stars
| name | histolab |
| description | 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. |
| license | Apache-2.0 license |
| compatibility | Requires Python 3.8–3.11 (histolab 0.7.0), OpenSlide system libraries, and Linux or macOS. Sample data via histolab.data requires pooch. |
| metadata | version: "1.1" skill-author: K-Dense Inc. |
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)
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:
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 to processed_path
from pathlib import Path
Path(slide.processed_path).mkdir(parents=True, exist_ok=True)
slide.thumbnail.save(Path(slide.processed_path) / f"{slide.name}_thumbnail.png")
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:
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 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:
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)
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:
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)
Standardize staining appearance across slides for deep learning (added in histolab 0.6.0).
Key classes: MacenkoStainNormalizer, ReinhardStainNormalizer
from histolab.stain_normalizer import MacenkoStainNormalizer, ReinhardStainNormalizer
from PIL import Image
target = Image.open("reference_stain.png") # Style reference slide/tile
source = Image.open("slide_to_normalize.png")
normalizer = MacenkoStainNormalizer()
normalizer.fit(target)
normalized = normalizer.transform(source)
normalized.save("normalized.png")
Use ReinhardStainNormalizer() for Reinhard color transfer. Fit on a representative target image, then transform source tiles or thumbnails. See references/filters_preprocessing.md for filter-based alternatives.
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:
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()
Quick sampling of diverse tissue regions for initial analysis.
from histolab.slide import Slide
from histolab.tiler import RandomTiler
from pathlib import Path
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}")
Path(slide.processed_path).mkdir(parents=True, exist_ok=True)
slide.thumbnail.save(Path(slide.processed_path) / f"{slide.name}_thumbnail.png")
# 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.
from 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.
from 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.
from 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
Path(slide.processed_path).mkdir(parents=True, exist_ok=True)
slide.thumbnail.save(Path(slide.processed_path) / f"{slide.name}_thumbnail.png")
# Extract tiles
tiler.extract(slide)
print(f"Completed: {slide_path.name}")
Handle slides with artifacts, annotations, or unusual staining.
from 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)
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.
Prerequisites
Time Estimate
15-45 minutes depending on use case complexity
Steps
Common Pitfalls
✓ Do
✗ Don't
💡 Pro Tips
✓ Use when
Use when skill capabilities match your task, clear ROI on time saved, and you can validate outputs. Best for repetitive tasks, learning, and quality improvement.
✗ Avoid when
Avoid when task requires deep expertise you can't validate, involves sensitive decisions, or when learning process is more valuable than speed of completion.
K-Dense-AI/scientific-agent-skills
K-Dense-AI/scientific-agent-skills
K-Dense-AI/scientific-agent-skills
K-Dense-AI/scientific-agent-skills
google-deepmind/science-skills
google-deepmind/science-skills
histolab reduced setup friction for our internal harness; good balance of opinion and flexibility.
Registry listing for histolab matched our evaluation — installs cleanly and behaves as described in the markdown.
histolab is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.
Useful defaults in histolab — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
Solid pick for teams standardizing on skills: histolab is focused, and the summary matches what you get after install.
We added histolab from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
Useful defaults in histolab — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
histolab is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.
Keeps context tight: histolab is the kind of skill you can hand to a new teammate without a long onboarding doc.
histolab has been reliable in day-to-day use. Documentation quality is above average for community skills.
showing 1-10 of 56