Lung Segmentation
November 12, 2025 ยท View on GitHub
This repository provides source code for lung segmentation using Deep Multi-Magnification Network. Deep Multi-Magnification Network automatically segments multiple tissue subtypes by a set of patches from multiple magnifications in histopathology whole slide images. The original Deep Multi-Magnification Network paper is published here and its training and inference codes can be found here.
Prerequisites
- Python 3.6.7
- Pytorch 1.3.1
- OpenSlide 1.1.1
- Albumentations
Inference
The main inference codes are slidereader_coords.py and inference.py. You first need to run slidereader_coords.py to generate patch coordinates to be segmented in input whole slide images. After generating patch coordinates, you may run inference.py to generate segmentation predictions of input whole slide images. The segmentation predictions will be saved under imgs/ by default.
You may need to update the following variables before running slidereader_coords.py:
slides_to_read: the list of whole slide imagescoord_file: an output file listing all patch coordinates
In addition to model_path and out_path, you may need to update the following variables before running inference.py:
n_classes: the number of tissue subtype classes + 1test file: the list of patch coordinates generated byslidereader_coords.pydata_path: the path where whole slide images are located
Please download the pretrained lung segmentation model here.
Note that segmentation predictions will be generated in 4-bit BMP format. The size limit for 4-bit BMP files is 232 pixels.
License
This project is under the CC-BY-NC 4.0 license. See LICENSE for details. (c) MSK
Acknowledgments
- This code is inspired by pytorch-semseg and MICCAI 2017 Robotic Instrument Segmentation.
Reference
If you find our work useful, please cite our paper:
@article{ho2025,
title={Deep Learning-Based Segmentation of Lung Adenocarcinoma Whole-Slide Images for Objective Grading, Tumor Spread Through Air Spaces Identification, and Mutation Prediction},
author={Ho, David Joon and Chang, Jason C. and Aly, Rania G. and Nguyen, Hai Cao Truong and Adusumilli, Prasad S. and Fuchs, Thomas J. and Travis, William D. and Vanderbilt, Chad M.},
journal={Modern Pathology},
year={2025},
month={December},
volume={38},
number={12},
pages={100907}
}
