JoHof/lungmask
Automated lung segmentation in CT
What it solves
Reading CT scans of the lungs is harder when the patient has severe conditions like tumors, fluid buildup (effusions), or heavy scarring (fibrosis). Standard tools often fail to outline the lungs cleanly in these cases. This project provides trained U-net models that automatically segment (outline) the lungs in CT images, even when dense pathologies are present. It also offers models that separate the lungs into left and right, or into individual lobes, and can fuse results to combine strengths.
How it works
The package includes four pre-trained U-net models:
- U-net(R231) – The default model. It works on individual CT slices, extracts the right and left lungs separately, and includes air pockets, tumors, and effusions. It does not include the trachea. Trained on a diverse dataset.
- U-net(LTRCLobes) – Trained on a subset of the LTRC dataset. It separates the lungs into five lobes, but performs poorly when dense pathologies are present or when the fissures between lobes aren’t visible on every slice.
- U-net(LTRCLobes_R231) – Runs both the R231 and LTRCLobes models and fuses the results. False negatives from LTRCLobes are filled by R231 predictions and mapped to a neighboring lobe label; false positives are removed. This fusion is computationally heavy and can take several minutes per volume.
- U-net(R231CovidWeb) – A variant of R231 that was additionally trained on COVID-19 CT slices that were mapped back from regular image formats to Hounsfield units (HU). Useful for cropped, annotated, or compressed web images.
All models are trained U-nets, a type of neural network for image segmentation. The package can run as a command-line tool or as a Python module. It uses SimpleITK for image I/O (or numpy arrays directly, as of version 0.2.9). GPU support speeds up processing significantly (seconds vs. minutes).
Who it’s for
- Researchers and clinicians working with lung CT data, especially those dealing with severe pathologies or COVID-19 cases.
- Developers who need automated lung segmentation in their Python pipelines or as a CLI tool.
- Anyone who wants to distinguish left/right lungs or individual lobes in CT volumes.
Highlights
- Four ready-to-use models tailored to different needs (default, lobes, fusion, COVID-adjusted).
- Handles dense pathologies that confuse other methods.
- Simple install via pip or conda, and easy Python API (
LMInferer). - Can process DICOM directories automatically, finding the largest volume.
- Supports both GPU (fast) and CPU (slow) inference.
- Includes a model-fusion option to combine lobe and whole-lung segmentations.
Related
- Project
- Project
- Project
- Project
- Project