histolab
它能做什么
Histolab 是一个用于准备显微镜切片图像的工具。它可以帮你选取这些图像中的特定部分(图块)用于分析,统一颜色使其保持一致,并为后续研究整理数据。
适用场景
- ✓当你需要从切片图像中选取特定部分进行分析时。
- ✓当你想统一不同切片图像的颜色外观时。
- ✓当你需要为训练人工智能模型整理一组切片图像时。
技能链接
https://github.com/K-Dense-AI/scientific-agent-skills/blob/main/skills/histolab/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“从 'example.svs' 切片中随机选取 100 个 512x512 像素的图块,重点选择组织占比至少为 80% 的区域。”
每周 5 个新技能,1 分钟读完。
工作原理
Histolab 会先识别切片中的组织区域,然后使用不同方法(随机、网格、基于评分)选择要提取的图像块。它还可以调整颜色,让所有图像看起来更加一致。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Histolab
When to use
Use Histolab to inspect WSI metadata, identify tissue, extract image tiles, and standardize H&E staining. Its masks and scores are image-processing heuristics; they do not diagnose cancer, count individual cells, or establish image quality.
Installation
Histolab 0.7.0 remains the latest published release as of the review date. Its release constraints require Python <3.12, NumPy <=1.24.4, scikit-image <0.19.4, SciPy <1.10.1, Pillow <11, and openslide-python 1.3.1. Keep this stack isolated from modern scientific environments. Windows is not supported by this Histolab release.
Install native OpenSlide for your system, then create a dedicated environment (Python 3.10 was tested):
uv venv --python 3.10 .venv-histolab
uv pip install --python .venv-histolab/bin/python 'histolab==0.7.0' pooch matplotlib
.venv-histolab/bin/python -c 'import openslide; print(openslide.__library_version__)'
On macOS with Homebrew, brew install openslide installs the native library.
If the older Python binding cannot find it, launch Python with the library path
set immediately before Python starts:
env DYLD_FALLBACK_LIBRARY_PATH="$(brew --prefix openslide)/lib" .venv-histolab/bin/python -c 'import openslide; print(openslide.__library_version__)'
pooch is optional for remote examples. Start with a local slide or the tiny
bundled cmu_small_region sample; other sample functions may download hundreds
of megabytes. Exact mpp extraction also needs large-image and a matching
source plugin; see slide management.
Workflow
- Inspect
slide.dimensions,slide.levels(a list), andslide.level_dimensions(level)(a method). Check both MPP axes in metadata. - Select physical field of view and pixel resolution; level numbers are not interchangeable across scanners. Preserve level-0 coordinate bounds.
- Choose
TissueMaskfor all tissue sections orBiggestTissueBoxMaskfor the largest section's bounding box. Inspect the mask at its actual resolution. - Configure a tiler and preview with the same mask passed to extraction. Preview methods return a Pillow image; save or display that return value.
- Extract into a distinct per-slide/per-strategy directory. Count saved files, inspect representative tiles, and retain parameters, source IDs and QC flags.
- Split datasets by patient before training/validation/test tile assignment. Fit stain normalization targets on training data only and validate on held-out scanners. A seed reproduces sampling; it does not prevent patient leakage.
Quick start
Illustrative for a user-provided slide; the same API path is tested with small
local fixtures. n_tiles is an upper bound, not a promise of 100 valid tiles.
from pathlib import Path
from histolab.slide import Slide
from histolab.masks import TissueMask
from histolab.tiler import RandomTiler
output = Path("output/random_tiles")
output.mkdir(parents=True, exist_ok=True)
slide = Slide("slide.svs", processed_path=output)
mask = TissueMask()
slide.locate_mask(mask).save(output / "mask_preview.png")
tiler = RandomTiler(
tile_size=(512, 512), n_tiles=100, level=0, seed=42,
check_tissue=True, tissue_percent=80.0, prefix="random_",
)
tiler.locate_tiles(slide, extraction_mask=mask).save(output / "tile_preview.png")
tiler.extract(slide, extraction_mask=mask)
print("[OK] Saved tiles:", len(list(output.glob("random_tile_*.png"))))
extraction_mask belongs to extract() and locate_tiles(), not to the tiler
constructor. locate_tiles() has no n_tiles argument. Previewing runs tile
selection again, so it may be expensive; use a separate small tiler for initial
exploration, then preview the final configuration before committing a large run.
Choose a strategy
| Tiler | Selection | Important limitation |
|---|---|---|
RandomTiler |
Seeded sampling, at most n_tiles, up to max_iter attempts |
May overlap, repeat, or miss rare structures |
GridTiler |
Grid within the extraction mask | Boundary tiles and tissue checks can leave gaps |
ScoreTiler |
Scores all eligible grid candidates; saves top n_tiles |
Lower output count does not avoid scoring all candidates |
For grids, stride in each axis is tile size minus pixel_overlap; positive
…
常见问题
Histolab 能诊断疾病吗?
不能。Histolab 不能诊断疾病,它是用于准备和分析图像的工具,而不是用于医学诊断的。
我可以在任何电脑上使用 Histolab 吗?
最新版本(0.7.0)不兼容 Windows,并且需要特定版本的其他 Python 库。建议你单独创建一个环境来使用它。
什么是“tiles”(图块)?
“Tiles”是从较大图像中截取的小块或方格。在 Histolab 中,它们是从显微镜切片图像中提取出来用于分析的部分。
详情
作者的原始描述
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.
热度
- GitHub 星标
- 51k
- 排名
- #3476
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …