foryourhealth111-pixel/Vibe-Skills / bundled/skills/histolab
histolab
VerifiedLightweight 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.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 20.0 KB |
| references/filters_preprocessing.md | markdown | 12.4 KB |
| references/slide_management.md | markdown | 4.6 KB |
| references/tile_extraction.md | markdown | 11.0 KB |
| references/tissue_masks.md | markdown | 7.1 KB |
| references/visualization.md | markdown | 13.6 KB |
references/slide_management.md
View on GitHub# Slide Management
## Overview
The `Slide` class is the primary interface for working with whole slide images (WSI) in histolab. It provides methods to load, inspect, and process large histopathology images stored in various formats.
## Initialization
```python
from histolab.slide import Slide
# Initialize a slide with a WSI file and output directory
slide = Slide(processed_path="path/to/processed/output",
slide_path="path/to/slide.svs")
```
**Parameters:**
- `slide_path`: Path to the whole slide image file (supports multiple formats: SVS, TIFF, NDPI, etc.)
- `processed_path`: Directory where processed outputs (tiles, thumbnails, etc.) will be saved
## Loading Sample Data
Histolab provides built-in sample datasets from TCGA for testing and demonstration:
```python
from histolab.data import prostate_tissue, ovarian_tissue, breast_tissue, heart_tissue, kidney_tissue
# Load prostate tissue sample
prostate_svs, prostate_path = prostate_tissue()
slide = Slide(prostate_path, processed_path="output/")
```
Available sample datasets:
- `prostate_tissue()`: Prostate tissue sample
- `ovarian_tissue()`: Ovarian tissue sample
- `breast_tissue()`: Breast tissue sample
- `heart_tissue()`: Heart tissue sample
- `kidney_tissue()`: Kidney tissue sample
## Key Properties
### Slide Dimensions
```python
# Get slide dimensions at level 0 (highest resolution)
width, height = slide.dimensions
# Get dimensions at specific pyramid level
level_dimensions = slide.level_dimensions
# Returns tuple of (width, height) for each level
```
### Magnification Information
```python
# Get base magnification (e.g., 40x, 20x)
base_mag = slide.base_mpp # Microns per pixel at level 0
# Get all available levels
num_levels = slide.levels # Number of pyramid levels
```
### Slide Properties
```python
# Access OpenSlide properties dictionary
properties = slide.properties
# Common properties include:
# - slide.properties['openslide.objective-power']: Objective power
# - slide.properties['openslide.mpp-x']: Microns per pixel in X
# - slide.properties['openslide.mpp-y']: Microns per pixel in Y
# - slide.properties['openslide.vendor']: Scanner vendor
```
## Thumbnail Generation
```python
# Get thumbnail at specific size
thumbnail = slide.thumbnail
# Save thumbnail to disk
slide.save_thumbnail() # Saves to processed_path
# Get scaled thumbnail
scaled_thumbnail = slide.scaled_image(scale_factor=32)
```
## Slide Visualization
```python
# Display slide thumbnail with matplotlib
import matplotlib.pyplot as plt
plt.figure(figsize=(10, 10))
plt.imshow(slide.thumbnail)
plt.title(f"Slide: {slide.name}")
plt.axis('off')
plt.show()
```
## Extracting Regions
```python
# Extract region at specific coordinates and level
region = slide.extract_region(
location=(x, y), # Top-left coordinates at level 0
size=(width, height), # Region size
level=0 # Pyramid level
)
```
## Working with Pyramid Levels
WSI files use a pyramidal structure with multiple resolution levels:
- Level 0: Highest resolution (native scan resolution)
- Level 1+: Progressively lower resolutions for faster access
```python
# Check available levels
for level in range(slide.levels):
dims = slide.level_dimensions[level]
downsample = slide.level_downsamples[level]
print(f"Level {level}: {dims}, downsample: {downsample}x")
```
## Slide Name and Path
```python
# Get slide filename without extension
slide_name = slide.name
# Get full path to slide file
slide_path = slide.scaled_image
```
## Best Practices
1. **Always specify processed_path**: Organize outputs in dedicated directories
2. **Check dimensions before processing**: Large slides can exceed memory limits
3. **Use appropriate pyramid levels**: Extract tiles at levels matching your analysis resolution
4. **Preview with thumbnails**: Use thumbnails for quick visualization before heavy processing
5. **Monitor memory usage**: Level 0 operations on large slides require significant RAM
## Common Workflows
### Slide Inspection Workflow
```python
from histolab.slide import Slide
# Load slide
slide = Slide("slide.svs", processed_path="output/")
# Inspect properties
print(f"Dimensions: {slide.dimensions}")
print(f"Levels: {slide.levels}")
print(f"Magnification: {slide.properties.get('openslide.objective-power', 'N/A')}")
# Save thumbnail for review
slide.save_thumbnail()
```
### Multi-Slide Processing
```python
import os
from pathlib import Path
slide_dir = Path("slides/")
output_dir = Path("processed/")
for slide_path in slide_dir.glob("*.svs"):
slide = Slide(slide_path, processed_path=output_dir / slide_path.stem)
# Process each slide
print(f"Processing: {slide.name}")
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |