Description
HistoSlice makes is easy to prepare your histological slide images for deep
learning models. You can easily cut large slide images into smaller tiles and then
preprocess those tiles (remove tiles with shitty tissue, finger marks etc).
Installation
uv add histoslice
# or
pip install histoslice
Usage
Typical workflow for training deep learning models with histological images is the following:
- Cut each slide image into smaller tile images.
- Preprocess smaller tile images by removing tiles with bad tissue, staining artifacts.
histoslice --input './train_images/*.tiff' --output ./tiles --width 512 --overlap 0.5 --max-background 0.5 --backend pyvips --metrics --thumbnail
Or you can use the HistoSlice python API to do the same thing!
from histoslice import SlideReader
# Read slide image.
reader = SlideReader("./slides/slide_with_ink.jpeg")
# Detect tissue.
threshold, tissue_mask = reader.get_tissue_mask(level=-1)
# Extract overlapping tile coordinates with less than 50% background.
tile_coordinates = reader.get_tile_coordinates(
tissue_mask, width=512, overlap=0.5, max_background=0.5
)
# Save tile images with image metrics for preprocessing.
tile_metadata, failures = reader.save_regions(
"./train_tiles/",
tile_coordinates,
threshold=threshold,
save_metrics=True,
save_thumbnail=True
)
if failures:
print(f"Some tiles failed: {len(failures)}")
Let's take a look at the output and visualise the thumbnails.
train_tiles
└── slide_with_ink
├── metadata.parquet # tile metadata
├── failures.json # per-tile failures (only written if any failures occur)
├── properties.json # tile properties
├── thumbnail.jpeg # thumbnail image (or .png if JPEG support is unavailable)
├── thumbnail_tiles.jpeg # thumbnail with tiles (or .png if JPEG support is unavailable)
├── thumbnail_tissue.jpeg # thumbnail of the tissue mask (or .png if JPEG support is unavailable)
└── tiles [390 entries exceeds filelimit, not opening dir]
As we can see from the above images, histological slide images often contain areas that we would not like to include into our training data. Might seem like a daunting task but let's try it out!
from histoslice.utils import OutlierDetector
# Let's wrap the tile metadata with a helper class.
detector = OutlierDetector(tile_metadata)
# Cluster tiles based on image metrics.
clusters = detector.cluster_kmeans(num_clusters=4, random_state=666)
# Visualise first cluster.
reader.get_annotated_thumbnail(
image=reader.read_level(-1), coordinates=detector.coordinates[clusters == 0]
)
Now we can mark tiles in cluster 0 as outliers!
Metadata
Release files for histoslice 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| histoslice-0.6.0.tar.gz | 6.3 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| histoslice-0.6.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.4 MB
Release files / histoslice-0.6.0.tar.gz
| Download URL | histoslice-0.6.0.tar.gz |
|---|---|
| Size | 6.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b4b74e9048a2ab846190f2257b4aa8f36c06ce04a33943639ee5e1c4e3a768dc
|
|
BLAKE2b-256 checksum How to use checksums |
c3ea775f5078fa6d3fb0a61d4755854fe29ec27c3e3e2ad8d021ff84f6eaa8bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 25, 2026.
Transparency logRelease files / histoslice-0.6.0-py3-none-any.whl
| Download URL | histoslice-0.6.0-py3-none-any.whl |
|---|---|
| Size | 50.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
984ddb04f3b9d9c2bf230287b60fa7dff44336714dd4af9aa43b245096946be7
|
|
BLAKE2b-256 checksum How to use checksums |
2f4afb8ff135c748fe192bdb7c674eb474e80a6c6988173d734776e110262eef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 25, 2026.
Transparency log