{"slug":"alterlab-histolab","title":"alterlab-histolab","summary":"Extract and preprocess tiles from whole-slide images (WSI) with histolab — OpenSlide-backed slide loading, tissue detection and masks, Random/Grid/Score tile extraction, and image/morphological filters for H&E preprocessing. Use when the user needs lightweight WSI slide preproces","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-09-23T18:56:55.118638Z","repo":{"url":"https://github.com/AlterLab-IEU/AlterLab-Academic-Skills","stars":68,"forks":13,"license":"MIT","updatedAt":"2026-09-23T13:42:59Z"},"bodyHtml":"<hr>\n<h2>name: alterlab-histolab\ndescription: Extract and preprocess tiles from whole-slide images (WSI) with histolab — OpenSlide-backed slide loading, tissue detection and masks, Random/Grid/Score tile extraction, and image/morphological filters for H&amp;E preprocessing. Use when the user needs lightweight WSI slide preprocessing — building tile datasets for ML training, tissue segmentation, or quick tile-based inspection of histopathology slides. For end-to-end computational-pathology, deep-learning model training, nucleus segmentation, or multiplexed/spatial-proteomics (CODEX, Vectra) pipelines prefer alterlab-pathml instead. Part of the AlterLab Academic Skills suite.\nlicense: Apache-2.0\nallowed-tools: Read Write Edit Bash(python:<em>) Bash(uv:</em>)\ncompatibility: \"Runs under <code>uv run python</code> with histolab 0.7.0 (still the latest release, Feb 2024) in a <strong>dedicated environment</strong>: it requires Python &gt;= 3.8, &lt; 3.12 and pins numpy &lt;= 1.24.4, scipy &lt; 1.10.1, scikit-image &lt; 0.19.4 and openslide-python 1.3.1 — it will not co-install with a modern numpy 2.x / Python 3.12+ stack. The OpenSlide C library must also be present (<code>uv pip install openslide-bin</code>, or <code>brew install openslide</code> / <code>apt install libopenslide0</code>). No API key or account required.\"\nmetadata:\nskill-author: AlterLab\nversion: \"1.1.0\"\nlast_updated: \"2026-09-23\"</h2>\n<h1>Histolab</h1>\n<h2>Overview</h2>\n<p>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.</p>\n<h2>When to Use This Skill</h2>\n<p>Use histolab for lightweight WSI tile pipelines: tissue detection, building tile datasets for ML training, H&amp;E stain handling, and quick tile-based analysis of histopathology slides. For advanced spatial proteomics, multiplexed imaging, or full deep-learning pathology pipelines, use <code>alterlab-pathml</code> instead.</p>\n<h3>Does NOT Trigger</h3>\n<table>\n<thead>\n<tr>\n<th>Scenario</th>\n<th>Use Instead</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>End-to-end computational pathology, nucleus segmentation, multiplexed imaging (CODEX/Vectra)</td>\n<td><code>alterlab-pathml</code></td>\n</tr>\n<tr>\n<td>Training the downstream classifier on the extracted tiles</td>\n<td><code>alterlab-pytorch-lightning</code></td>\n</tr>\n<tr>\n<td>DICOM whole-slide or radiology images rather than SVS/NDPI</td>\n<td><code>alterlab-pydicom</code>, <code>alterlab-imaging-data-commons</code></td>\n</tr>\n<tr>\n<td>Spatial transcriptomics on tissue sections</td>\n<td><code>alterlab-squidpy-spatial</code></td>\n</tr>\n<tr>\n<td>Managing/versioning the slide collection itself</td>\n<td><code>alterlab-omero</code>, <code>alterlab-lamindb</code></td>\n</tr>\n</tbody>\n</table>\n<h2>Installation</h2>\n<pre><code># histolab 0.7.0 needs Python &gt;= 3.8, &lt; 3.12 and numpy 1.x — give it its own env\nuv venv --python 3.11 .venv-histolab\nuv pip install --python .venv-histolab \"histolab==0.7.0\" openslide-bin\n</code></pre>\n<p>Two constraints that bite in a 2026 toolchain:</p>\n<ol>\n<li><strong>Pinned scientific stack.</strong> 0.7.0 (Feb 2024, still the latest release) requires\n<code>numpy &lt;= 1.24.4</code>, <code>scipy &lt; 1.10.1</code>, <code>scikit-image &lt; 0.19.4</code> and\n<code>openslide-python 1.3.1</code>. It cannot share an environment with a numpy 2.x / Python\n3.12+ project — resolve this with a separate venv rather than by loosening pins.</li>\n<li><strong>OpenSlide is a C library</strong>, not bundled with the wheel. The simplest fix is the\n<code>openslide-bin</code> wheel (prebuilt binaries); otherwise <code>brew install openslide</code> on macOS\nor <code>apt install libopenslide0</code> on Debian/Ubuntu. Without it, <code>import histolab.slide</code>\nfails with <code>Couldn't locate OpenSlide dylib</code>.</li>\n</ol>\n<p>The examples below target histolab 0.7.0; the API differs in older releases.</p>\n<h2>Core Workflow</h2>\n<ol>\n<li><strong>Load</strong> the slide with <code>Slide(path, processed_path=...)</code> and inspect dimensions/levels.</li>\n<li><strong>Detect tissue</strong> with a mask (<code>TissueMask</code> or <code>BiggestTissueBoxMask</code>).</li>\n<li><strong>Preview</strong> tile locations with <code>tiler.locate_tiles(slide)</code> before committing.</li>\n<li><strong>Extract</strong> tiles with one of three tilers (Random/Grid/Score).</li>\n</ol>\n<p>Minimal example:</p>\n<pre><code>from histolab.slide import Slide\nfrom histolab.tiler import RandomTiler\n\nslide = Slide(\"slide.svs\", processed_path=\"output/\")\n# n_tiles, level, seed are CONSTRUCTOR args — not args to locate_tiles/extract.\ntiler = RandomTiler(tile_size=(512, 512), n_tiles=100, level=0, seed=42)\ntiler.locate_tiles(slide)   # preview locations on the thumbnail first\ntiler.extract(slide)        # writes PNGs into processed_path\n</code></pre>\n<p><strong>API gotcha (histolab 0.7.0):</strong> <code>locate_tiles()</code> and <code>extract()</code> take only\n<code>slide</code>, an optional <code>extraction_mask</code>, and logging/styling kwargs — they do\n<strong>not</strong> accept <code>n_tiles</code>. Set <code>n_tiles</code> (and <code>seed</code>, <code>level</code>, <code>tile_size</code>,\n<code>check_tissue</code>, <code>tissue_percent</code>) on the tiler constructor. The\n<code>extraction_mask</code> is passed to <code>extract()</code>/<code>locate_tiles()</code>, never to the\nconstructor.</p>\n<p>Full copy-pasteable pipelines (quick start, 5 end-to-end workflows, and per-capability examples) live in <code>references/workflows.md</code>.</p>\n<h2>Core Capabilities</h2>\n<h3>1. Slide Management</h3>\n<p>Load, inspect, and work with WSI files (SVS, TIFF, NDPI, etc.): access metadata\n(dimensions, magnification, properties), generate thumbnails, and work with\npyramidal/multi-level structures. Key class: <code>Slide</code>.</p>\n<p>See <code>references/slide_management.md</code> for slide initialization, built-in sample\ndatasets (<code>prostate_tissue</code>, <code>ovarian_tissue</code>, <code>breast_tissue</code>, <code>heart_tissue</code>,\n<code>aorta_tissue</code>, plus pen-marked and IHC samples), pyramid levels, and\nmulti-slide processing.</p>\n<h3>2. Tissue Detection and Masks</h3>\n<p>Automatically identify tissue regions and filter background/artifacts. Key\nclasses: <code>TissueMask</code> (all tissue regions), <code>BiggestTissueBoxMask</code> (bounding box\nof largest region — the default), and <code>BinaryMask</code> (base class for custom masks).</p>\n<p>Choosing a mask:</p>\n<ul>\n<li><code>TissueMask</code>: multiple tissue sections, comprehensive analysis</li>\n<li><code>BiggestTissueBoxMask</code>: single main section, exclude artifacts (default)</li>\n<li>Custom <code>BinaryMask</code>: specific ROI, exclude annotations, custom segmentation</li>\n</ul>\n<p>See <code>references/tissue_masks.md</code> for how detection filters work, visualizing\nmasks with <code>locate_mask()</code>, and custom rectangular / annotation-exclusion masks.</p>\n<h3>3. Tile Extraction</h3>\n<p>Extract smaller regions from large WSI using one of three strategies:</p>\n<ul>\n<li><strong>RandomTiler</strong> — fixed number of randomly positioned tiles. Best for sampling\ndiverse regions, exploration, training data. Key params: <code>n_tiles</code>, <code>seed</code>.</li>\n<li><strong>GridTiler</strong> — systematic grid across tissue. Best for complete coverage,\nspatial analysis, reconstruction. Key param: <code>pixel_overlap</code>.</li>\n<li><strong>ScoreTiler</strong> — top-ranked tiles by scoring function. Best for informative\nregions, quality-driven selection. Key param: <code>scorer</code> (NucleiScorer,\nCellularityScorer, custom).</li>\n</ul>\n<p>Common parameters: <code>tile_size</code>, <code>level</code> (0 = highest res), <code>check_tissue</code>,\n<code>tissue_percent</code> (default 80%), <code>extraction_mask</code>. <strong>Always preview with\n<code>locate_tiles()</code> before extracting.</strong></p>\n<p>See <code>references/tile_extraction.md</code> for scorers, reporting, and advanced\n(multi-level, hierarchical) extraction patterns.</p>\n<h3>4. Filters and Preprocessing</h3>\n<p>Apply image-processing filters for tissue detection, QC, and preprocessing:</p>\n<ul>\n<li><strong>Image filters</strong> — <code>RgbToGrayscale</code>, <code>RgbToHsv</code>, <code>RgbToHed</code>, <code>OtsuThreshold</code>,\n<code>Invert</code>, <code>StretchContrast</code>, <code>HistogramEqualization</code>, <code>Lambda</code>.</li>\n<li><strong>Morphological filters</strong> — <code>BinaryDilation</code>, <code>BinaryErosion</code>, <code>BinaryOpening</code>,\n<code>BinaryClosing</code>, <code>RemoveSmallObjects</code>, <code>RemoveSmallHoles</code>.</li>\n<li><strong>Composition</strong> — <code>Compose</code> (in <code>histolab.filters.image_filters</code>) chains\nfilters into pipelines. Pass custom filters to a mask as positional varargs:\n<code>TissueMask(RgbToGrayscale(), OtsuThreshold(), ...)</code>.</li>\n</ul>\n<p>See <code>references/filters_preprocessing.md</code> for filter chaining, common pipelines\n(tissue detection, pen removal, nuclei enhancement), and QC filters.</p>\n<h3>5. Visualization</h3>\n<p>Display slides, masks, tile locations, and extraction quality: thumbnails, mask\noverlays via <code>locate_mask()</code>, tile-location previews via <code>locate_tiles()</code>, tile\nmosaics, and score distributions.</p>\n<p>See <code>references/visualization.md</code> for mosaics, quality-assessment plots,\nmulti-slide comparison, and exporting high-resolution figures / PDF reports.</p>\n<h2>Reference Index</h2>\n<ul>\n<li><code>references/workflows.md</code> — quick start, per-capability examples, and 5\nend-to-end worked workflows (exploratory, grid, score-driven, multi-slide,\ncustom tissue detection).</li>\n<li><code>references/slide_management.md</code> — loading/inspecting slides, sample datasets,\npyramid levels, multi-slide processing.</li>\n<li><code>references/tissue_masks.md</code> — <code>TissueMask</code>/<code>BiggestTissueBoxMask</code>/<code>BinaryMask</code>,\ncustom masks, mask visualization and integration.</li>\n<li><code>references/tile_extraction.md</code> — Random/Grid/Score tiler comparison, scorers,\nCSV reporting, advanced extraction patterns.</li>\n<li><code>references/filters_preprocessing.md</code> — image + morphological filters, filter\ncomposition, preprocessing pipelines, QC filters.</li>\n<li><code>references/visualization.md</code> — thumbnails, mask/tile previews, mosaics,\nquality plots, figure export.</li>\n<li><code>references/best_practices.md</code> — best practices, common use cases, and\ntroubleshooting (no tiles, background tiles, slow extraction, artifacts).</li>\n</ul>\n<p>Load the specific reference file you need for detailed implementation guidance,\ntroubleshooting, or advanced features.</p>\n<p>Part of the AlterLab Academic Skills suite.</p>\n","files":[{"path":"evals/evals.json","sizeBytes":4960,"isText":true},{"path":"references/best_practices.md","sizeBytes":3835,"isText":true},{"path":"references/filters_preprocessing.md","sizeBytes":12137,"isText":true},{"path":"references/slide_management.md","sizeBytes":5428,"isText":true},{"path":"references/tile_extraction.md","sizeBytes":12104,"isText":true},{"path":"references/tissue_masks.md","sizeBytes":7499,"isText":true},{"path":"references/visualization.md","sizeBytes":14163,"isText":true},{"path":"references/workflows.md","sizeBytes":9906,"isText":true},{"path":"SKILL.md","sizeBytes":9290,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-09-23T18:57:29.725138Z","sha256":"1A951B41A02F199CAE22BE77690A8F2A912CACE5D6A549F368854E42A3897083","sizeBytes":28194},"review":null,"source":{"repositoryUrl":"https://github.com/AlterLab-IEU/AlterLab-Academic-Skills","path":"skills/bioinformatics/alterlab-histolab","license":"MIT","commit":"e4836c08a20da195a11f30f203a8cf23ec30aa95","subtreeSha":"0EE83EAA72120C09C8EC1DA0DC66A743EFF3ADADD497BD039331A7A69090D2D5","lastSyncedAt":"2026-09-23T18:56:52.297238Z"},"reviewedAt":"2026-09-23T18:58:50.059141Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/AlterLab-IEU/AlterLab-Academic-Skills/tree/main/skills/bioinformatics/alterlab-histolab"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install alterlab-ieu-alterlab-academic-skills@llmmart"},{"target":"git","command":"git clone https://github.com/AlterLab-IEU/AlterLab-Academic-Skills.git"}]}