{"id":13708784,"url":"https://github.com/EIDOSLAB/torchstain","last_synced_at":"2025-05-06T15:31:09.922Z","repository":{"id":44709264,"uuid":"323590093","full_name":"EIDOSLAB/torchstain","owner":"EIDOSLAB","description":"Stain normalization tools for histological analysis and computational pathology","archived":false,"fork":false,"pushed_at":"2025-01-13T15:36:19.000Z","size":2646,"stargazers_count":138,"open_issues_count":16,"forks_count":25,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-02T09:06:40.377Z","etag":null,"topics":["computational-pathology","digital-pathology","histopathology","medical-imaging","numpy","python","pytorch","stain-normalization","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EIDOSLAB.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-22T10:13:08.000Z","updated_at":"2025-04-19T08:55:45.000Z","dependencies_parsed_at":"2024-05-12T22:46:28.446Z","dependency_job_id":"46e1096c-3a43-4059-8f67-2d11fce96dd1","html_url":"https://github.com/EIDOSLAB/torchstain","commit_stats":{"total_commits":156,"total_committers":3,"mean_commits":52.0,"dds":0.5,"last_synced_commit":"4365a652058a5083ce90ca8e6ba58ba246a6bfbd"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EIDOSLAB%2Ftorchstain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EIDOSLAB%2Ftorchstain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EIDOSLAB%2Ftorchstain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EIDOSLAB%2Ftorchstain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EIDOSLAB","download_url":"https://codeload.github.com/EIDOSLAB/torchstain/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252712847,"owners_count":21792380,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computational-pathology","digital-pathology","histopathology","medical-imaging","numpy","python","pytorch","stain-normalization","tensorflow"],"created_at":"2024-08-02T23:00:32.493Z","updated_at":"2025-05-06T15:31:09.915Z","avatar_url":"https://github.com/EIDOSLAB.png","language":"Python","readme":"# torchstain\n\n[![License](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)\n[![Full Tests](https://github.com/EIDOSLAB/torchstain/actions/workflows/tests_full.yml/badge.svg)](https://github.com/EIDOSLAB/torchstain/actions/workflows/tests_full.yml)\n[![Pip Downloads](https://img.shields.io/pypi/dm/torchstain?label=pip%20downloads\u0026logo=python)](https://pypi.org/project/torchstain/)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7692014.svg)](https://doi.org/10.5281/zenodo.7692014)\n\nGPU-accelerated stain tools for histopathological images. Compatible with PyTorch, TensorFlow, and Numpy.\n\nNormalization algorithms currently implemented:\n- Macenko [\\[1\\]](#reference) (ported from [numpy implementation](https://github.com/schaugf/HEnorm_python))\n- Reinhard [\\[2\\]](#reference)\n- Modified Reinhard [\\[3\\]](#reference)\n- Multi-target Macenko [\\[4\\]](#reference)\n\nAugmentation algorithms currently implemented:\n- Macenko-Aug [\\[1\\]](#reference) (inspired by [StainTools](https://github.com/Peter554/StainTools))\n\n## Installation\n\n```bash\npip install torchstain\n```\n\nTo install a specific backend use either ```torchstain[torch]``` or ```torchstain[tf]```. The numpy backend is included by default in both.\n\n## Example Usage\n\n```python\nimport torch\nfrom torchvision import transforms\nimport torchstain\nimport cv2\n\ntarget = cv2.cvtColor(cv2.imread(\"./data/target.png\"), cv2.COLOR_BGR2RGB)\nto_transform = cv2.cvtColor(cv2.imread(\"./data/source.png\"), cv2.COLOR_BGR2RGB)\n\nT = transforms.Compose([\n    transforms.ToTensor(),\n    transforms.Lambda(lambda x: x*255)\n])\n\nnormalizer = torchstain.normalizers.MacenkoNormalizer(backend='torch')\nnormalizer.fit(T(target))\n\nt_to_transform = T(to_transform)\nnorm, H, E = normalizer.normalize(I=t_to_transform, stains=True)\n```\n\n![alt text](data/result.png)\n\n## Implemented algorithms\n\n| Algorithm | numpy | torch | tensorflow |\n|-|-|-|-|\n| Macenko | \u0026check; | \u0026check; | \u0026check; |\n| Reinhard | \u0026check; | \u0026check; | \u0026check; |\n| Modified Reinhard | \u0026check; | \u0026check; | \u0026check; |\n| Multi-target Macenko | \u0026cross; | \u0026check; | \u0026cross; |\n| Macenko-Aug | \u0026check; | \u0026check; | \u0026check; |\n\n## Backend comparison\n\nRuntimes 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.\n\n|   size | numpy avg. time   | torch avg. time   | tf avg. time     |\n|--------|-------------------|-------------------|------------------|\n|    224 | 0.0182s ± 0.0016  | 0.0180s ± 0.0390  | 0.0048s ± 0.0002 |\n|    448 | 0.0880s ± 0.0224  | 0.0283s ± 0.0172  | 0.0210s ± 0.0025 |\n|    672 | 0.1810s ± 0.0139  | 0.0463s ± 0.0301  | 0.0354s ± 0.0018 |\n|    896 | 0.3013s ± 0.0377  | 0.0820s ± 0.0329  | 0.0713s ± 0.0008 |\n|   1120 | 0.4694s ± 0.0350  | 0.1321s ± 0.0237  | 0.1036s ± 0.0042 |\n|   1344 | 0.6640s ± 0.0553  | 0.1665s ± 0.0026  | 0.1663s ± 0.0021 |\n|   1568 | 1.1935s ± 0.0739  | 0.2590s ± 0.0088  | 0.2531s ± 0.0031 |\n|   1792 | 1.4523s ± 0.0207  | 0.3402s ± 0.0114  | 0.3080s ± 0.0188 |\n\n## Reference\n\n- [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.\n- [2] Reinhard, Erik et al. \"Color transfer between images.\" IEEE Computer Graphics and Applications. IEEE, 2001.\n- [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.\n- [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.\n\n## Citing\n\nIf you find this software useful for your research, please cite it as: \n\n```bibtex\n@software{barbano2022torchstain,\n  author       = {Carlo Alberto Barbano and André Pedersen},\n  title        = {EIDOSLAB/torchstain: v1.2.0-stable},\n  month        = aug,\n  year         = 2022,\n  publisher    = {Zenodo},\n  version      = {v1.2.0-stable},\n  doi          = {10.5281/zenodo.6979540},\n  url          = {https://doi.org/10.5281/zenodo.6979540}\n}\n```\n\nTorchstain was originally developed within the [UNITOPATHO](https://github.com/EIDOSLAB/UNITOPATHO) data collection, which you can cite as:\n\n```bibtex\n@inproceedings{barbano2021unitopatho,\n  title={UniToPatho, a labeled histopathological dataset for colorectal polyps classification and adenoma dysplasia grading},\n  author={Barbano, Carlo Alberto and Perlo, Daniele and Tartaglione, Enzo and Fiandrotti, Attilio and Bertero, Luca and Cassoni, Paola and Grangetto, Marco},\n  booktitle={2021 IEEE International Conference on Image Processing (ICIP)},\n  pages={76--80},\n  year={2021},\n  organization={IEEE}\n}\n```\n","funding_links":[],"categories":["Software"],"sub_categories":["Model"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEIDOSLAB%2Ftorchstain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FEIDOSLAB%2Ftorchstain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FEIDOSLAB%2Ftorchstain/lists"}