RepositoryPythonITItaly
EIDOSLAB

EIDOSLAB/torchstain

Stain normalization tools for histological analysis and computational pathology

194stars
31forks
8issues
2views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: stain-normalization

#1 Repository of the week

1
TINIX TRENDING·Topic: histopathology

#1 Repository of the week

1
TINIX TRENDING·Topic: computational-pathology

#1 Repository of the week

torchstain

License Full Tests Pip Downloads DOI

GPU-accelerated stain tools for histopathological images. Compatible with PyTorch, TensorFlow, and Numpy.

Normalization algorithms currently implemented:

Augmentation algorithms currently implemented:

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)
])

normalizer = torchstain.normalizers.MacenkoNormalizer(backend='torch')
normalizer.fit(T(target))

t_to_transform = T(to_transform)
norm, H, E = normalizer.normalize(I=t_to_transform, stains=True)

alt text

Implemented algorithms

Algorithmnumpytorchtensorflow
Macenko✓✓✓
Reinhard✓✓✓
Modified Reinhard✓✓✓
Multi-target Macenko✓✓✓
Macenko-Aug✓✓✓

Backend comparison

Runtimes using the Macenko algorithm using different backends. Metrics were calculated from 10 repeated runs for each quadratic image size on an Intel(R) Core(TM) i5-8365U CPU @ 1.60GHz.

sizenumpy avg. timetorch avg. timetf avg. time
2240.0182s ± 0.00160.0180s ± 0.03900.0048s ± 0.0002
4480.0880s ± 0.02240.0283s ± 0.01720.0210s ± 0.0025
6720.1810s ± 0.01390.0463s ± 0.03010.0354s ± 0.0018
8960.3013s ± 0.03770.0820s ± 0.03290.0713s ± 0.0008
11200.4694s ± 0.03500.1321s ± 0.02370.1036s ± 0.0042
13440.6640s ± 0.05530.1665s ± 0.00260.1663s ± 0.0021
15681.1935s ± 0.07390.2590s ± 0.00880.2531s ± 0.0031
17921.4523s ± 0.02070.3402s ± 0.01140.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.
  • [2] Reinhard, Erik et al. "Color transfer between images." IEEE Computer Graphics and Applications. IEEE, 2001.
  • [3] Roy, Santanu et al. "Modified Reinhard Algorithm for Color Normalization of Colorectal Cancer Histopathology Images". 2021 29th European Signal Processing Conference (EUSIPCO), IEEE, 2021.
  • [4] Ivanov, Desislav et al. "Multi-target stain normalization for histology slides". 2nd International Workshop on Medical Optical Imaging and Virtual Microscopy Image Analysis (MOVI 2024), MICCAI. 2024.

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-stable},
  month        = aug,
  year         = 2022,
  publisher    = {Zenodo},
  version      = {v1.2.0-stable},
  doi          = {10.5281/zenodo.6979540},
  url          = {https://doi.org/10.5281/zenodo.6979540}
}

Torchstain was originally developed within the UNITOPATHO data collection, which you can cite as:

@inproceedings{barbano2021unitopatho,
  title={UniToPatho, a labeled histopathological dataset for colorectal polyps classification and adenoma dysplasia grading},
  author={Barbano, Carlo Alberto and Perlo, Daniele and Tartaglione, Enzo and Fiandrotti, Attilio and Bertero, Luca and Cassoni, Paola and Grangetto, Marco},
  booktitle={2021 IEEE International Conference on Image Processing (ICIP)},
  pages={76--80},
  year={2021},
  organization={IEEE}
}

Similar Projects

Discover other similar projects and AI models.

RepositoryPython
rendeirolab/LazySlide

Accessible and interoperable whole slide image analysis for digital pathology in Python

333
Oct 6, 2026
RepositoryPython
huggingface/transformers

🤗 Transformers: the model-definition framework for state-of-the-art machine learning models in text, vision, audio, and multimodal models, for both inference and training.

169.5k
Dec 1, 2026
RepositoryPython
Comfy-Org/ComfyUI

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

149.6k
Dec 2, 2026
RepositoryC++
tensorflow/tensorflow

An Open Source Machine Learning Framework for Everyone

201.9k
Dec 1, 2026
RepositoryPython
TissueImageAnalytics/tiatoolbox

Computational Pathology Toolbox developed by TIA Centre, University of Warwick.

570
Nov 30, 2026
RepositoryPython
Dana-Farber-AIOS/pathml

Tools for computational pathology

469
Aug 14, 2026
RepositoryPython
dazhangyu123/ACMIL

Attention-Challenging Multiple Instance Learning for Whole Slide Image Classification (ECCV2024)

139
Apr 28, 2025
Repository
open-pathology/awesome-pathology

Awesome List of Digital and Computational Pathology Resources

140
Feb 11, 2026
Modelimage-feature-extraction
Aignostics/RudolfV-2

RudolfV 2 RudolfV 2 is a vision transformer based Foundation Model developed by Aignostics(https://www.aignostics.com/) for computational pathology. It uses a ViT-g/8 backbone and was pretrained on 300k whole slide images (WSIs). RudolfV 2 can serve...

♥0
1.4k
Aug 7, 2026