Skip to content

K-Dense-AI/scientific-agent-skills / skills/histolab

histolab

Verified

Extracts and preprocesses whole-slide histology image tiles with Histolab. Use for WSI inspection, tissue masks, random/grid/score-based tile extraction, H&E stain normalization, and tile dataset preparation. For multiplexed imaging or deep learning inference pipelines, use pathml.

references/typical_workflows.md

View on GitHub
# Typical workflows (Histolab 0.7.0)

These recipes use local inputs and distinct output directories. They are tested
with a small bundled SVS and synthetic images; parameter choices still need
validation for the user's tissue, scanner and study. Paths below are illustrative.
Do not derive train/validation/test splits from tiles after extraction: assign
patients first and preserve the mapping throughout preparation.

## Random, grid and scored extraction

This shared function previews the exact extraction mask and configuration,
separates previews from tiles, and verifies output rather than trusting logs.

<!-- recipe: extract-run -->
```python
from pathlib import Path
from histolab.slide import Slide
from histolab.masks import TissueMask
from histolab.tiler import ScoreTiler

def extract_run(slide_path, output_dir, tiler, mask=None):
    if tiler.mpp is not None:
        raise ValueError("This helper supports level-based extraction only")
    output_dir = Path(output_dir)
    output_dir.mkdir(parents=True, exist_ok=False)
    tiles_dir = output_dir / "tiles"
    tiles_dir.mkdir()
    slide = Slide(slide_path, processed_path=tiles_dir)
    if tiler.level not in slide.levels:
        raise ValueError("Choose an available slide level")
    mask = TissueMask() if mask is None else mask
    slide.thumbnail.save(output_dir / "thumbnail.png")
    slide.locate_mask(mask).save(output_dir / "mask.png")
    tiler.locate_tiles(slide, extraction_mask=mask).save(output_dir / "locations.png")
    options = {"extraction_mask": mask}
    if isinstance(tiler, ScoreTiler):
        options["report_path"] = str(output_dir / "scores.csv")
    tiler.extract(slide, **options)
    paths = sorted(tiles_dir.glob(f"*{tiler.suffix}"))
    if not paths:
        raise RuntimeError("No tiles saved; inspect mask, size, level and tissue threshold")
    return paths
```

The fresh-directory requirement preserves earlier runs. Failed extraction may
leave a partial new directory; inspect it before retrying into another directory.
This helper targets **level-based extraction**; configure and validate optional
MPP backends separately.

```python
from histolab.tiler import RandomTiler, GridTiler, ScoreTiler
from histolab.scorer import NucleiScorer

# Choose one recipe; each processes its input slide independently.
random_tiles = extract_run("slide.svs", "output/random", RandomTiler(
    tile_size=(256, 256), n_tiles=20, level=0, seed=42,
    check_tissue=True, tissue_percent=80.0,
))
grid_tiles = extract_run("slide.svs", "output/grid", GridTiler(
    tile_size=(256, 256), level=0, pixel_overlap=0,
    check_tissue=True, tissue_percent=80.0,
))
scored_tiles = extract_run("slide.svs", "output/scored", ScoreTiler(
    tile_size=(256, 256), level=0, n_tiles=10, scorer=NucleiScorer(),
    check_tissue=True,
))
```

Use the score-report plot in the visualization reference on `scores.csv`.
NucleiScorer selects nuclear-stain-rich regions, not validated high-quality or
malignant tissue. ScoreTiler evaluates the whole eligible grid even for ten
output tiles and can fail for degenerate constant scores.

## Cohort processing

```python
from pathlib import Path
from histolab.tiler import RandomTiler

for slide_path in sorted(Path("slides").glob("*.svs")):
    tiler = RandomTiler(tile_size=(256, 256), n_tiles=20, level=0, seed=42)
    paths = extract_run(slide_path, Path("output/cohort") / slide_path.stem, tiler)
    print("[OK]", slide_path.name, len(paths))
```

Resolve duplicate slide stems in the input manifest before using them as keys.
For every run, store the source slide ID/hash, patient and split, software
versions, level/MPP metadata, output pixel size, mask/filter parameters,
tiler/scorer parameters, seed, expected/actual tile count and any QC rejection.
Across scanners, equal level numbers do not imply equal physical resolution.
This sequential example does not validate parallel access or cohort-scale memory.

## Custom detection

Construct `TissueMask(*mask_filters)` using the filters reference and pass that
same object as `mask=custom_mask` to `extract_run`. Larger morphology thresholds
may discard small real tissue; compare results before and after the change.
`BiggestTissueBoxMask()` can instead restrict extraction to a largest-region
rectangle, at the cost of excluding other sections.

## Optional normalization

After extracting and inspecting RGB tiles, fit a Macenko or Reinhard normalizer
on a representative training-only target. Transform each tile, save to a distinct
normalized directory with the same source tile identifier, and preserve original
tiles and target provenance. Do not fit on held-out patient tissue or normalize
quantitative IHC measurements without a validated assay-specific protocol.
writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deploymentStars: 322kUpdated Claude CodeCodexVerifiedInstall
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: 198kUpdated Claude CodeCodexVerifiedInstall
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: 119kUpdated Claude CodeCodexVerifiedInstall
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: 118kUpdated Claude CodeCodexVerifiedInstall