Stain normalization tools for histological analysis and computational pathology
Project description
torchstain
GPU-accelerated stain normalization tools for histopathological images. Compatible with PyTorch, TensorFlow, and Numpy. Normalization algorithms currently implemented:
- Macenko et al. [1] (ported from numpy implementation)
Installation
pip install torchstain
To install a specific backend use either torchstain[torch]
or torchstain[tf]
. The numpy backend is included by default in both.
Example Usage
import torch
from torchvision import transforms
import torchstain
import cv2
target = cv2.cvtColor(cv2.imread("./data/target.png"), cv2.COLOR_BGR2RGB)
to_transform = cv2.cvtColor(cv2.imread("./data/source.png"), cv2.COLOR_BGR2RGB)
T = transforms.Compose([
transforms.ToTensor(),
transforms.Lambda(lambda x: x*255)
])
torch_normalizer = torchstain.normalizers.MacenkoNormalizer(backend='torch')
torch_normalizer.fit(T(target))
t_to_transform = T(to_transform)
norm, H, E = normalizer.normalize(I=t_to_transform, stains=True)
Implemented algorithms
Algorithm | numpy | torch | tensorflow |
---|---|---|---|
Macenko | ✓ | ✓ | ✓ |
Backend comparison
Results with 10 runs per size on a Intel(R) Core(TM) i5-8365U CPU @ 1.60GHz
size | numpy avg. time | torch avg. time | tf avg. time |
---|---|---|---|
224 | 0.0182s ± 0.0016 | 0.0180s ± 0.0390 | 0.0048s ± 0.0002 |
448 | 0.0880s ± 0.0224 | 0.0283s ± 0.0172 | 0.0210s ± 0.0025 |
672 | 0.1810s ± 0.0139 | 0.0463s ± 0.0301 | 0.0354s ± 0.0018 |
896 | 0.3013s ± 0.0377 | 0.0820s ± 0.0329 | 0.0713s ± 0.0008 |
1120 | 0.4694s ± 0.0350 | 0.1321s ± 0.0237 | 0.1036s ± 0.0042 |
1344 | 0.6640s ± 0.0553 | 0.1665s ± 0.0026 | 0.1663s ± 0.0021 |
1568 | 1.1935s ± 0.0739 | 0.2590s ± 0.0088 | 0.2531s ± 0.0031 |
1792 | 1.4523s ± 0.0207 | 0.3402s ± 0.0114 | 0.3080s ± 0.0188 |
Reference
- [1] Macenko, Marc, et al. "A method for normalizing histology slides for quantitative analysis." 2009 IEEE International Symposium on Biomedical Imaging: From Nano to Macro. IEEE, 2009.
Citing
If you find this software useful for your research, please cite it as:
@software{barbano2022torchstain,
author = {Carlo Alberto Barbano and
André Pedersen},
title = {EIDOSLAB/torchstain: v1.2.0-rc1},
month = aug,
year = 2022,
publisher = {Zenodo},
version = {v1.2.0-rc1},
doi = {10.5281/zenodo.6976410},
url = {https://doi.org/10.5281/zenodo.6976410}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
torchstain-1.2.0.tar.gz
(10.9 kB
view details)
Built Distribution
File details
Details for the file torchstain-1.2.0.tar.gz
.
File metadata
- Download URL: torchstain-1.2.0.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c46663bd231e4a276ee669e8e4589bbd26bd7cd9a703cf21c4806da63c31c953 |
|
MD5 | bfaca03b0eed60a4aebacc7f72e37396 |
|
BLAKE2b-256 | b5f5bd19a65cb588334d483a69fe4295e6d095a48624280a175bc2ba537ababe |
File details
Details for the file torchstain-1.2.0-py3-none-any.whl
.
File metadata
- Download URL: torchstain-1.2.0-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d398c568fb28822c53f548654293c0c0a91e9df5b3cea589037e21e0d6db90df |
|
MD5 | 4465d3e3d6b32000eb01b42ee2a4c98f |
|
BLAKE2b-256 | eac0410def84b7f363e582ebf645457b3f5f52ab3fa009c559c8e2f5e9d9b5f6 |