A web-based application for automated lung segmentation using deep learning, powered by Gradio and PyTorch. This tool allows users to upload lung images and obtain segmented outputs efficiently.
The application is running on Hugging Face, try it using this link!
If you don't have your own .tif image, the app includes a built-in example file that can be used directly from the UI by clicking "Try an example!".
You can load a remote .tif/.tiff by appending a file_url query parameter to the app URL. Prefer a direct-download link.
-
Example on Hugging Face: https://huggingface.co/spaces/qchapp/3d-lungs-segmentation/?file_url=https://zenodo.org/record/8099852/files/lungs_ct.tif?download=1
-
Example when running locally: http://127.0.0.1:7860/?file_url=https://zenodo.org/record/8099852/files/lungs_ct.tif?download=1 (or change to point to the corresponding local URL)
Notes:
- Large files may take time to download and render.
- Only .tif/.tiff files are supported.
- If your link isn’t a direct file URL (e.g., redirects to an HTML page), the download will fail. In that case, use the host’s “Direct download” URL or URL‑encode the value of file_url.
We recommend performing the installation in a clean Python environment.
The code requires python>=3.10, as well as pytorch>=2.0. Please install Pytorch first and separately following the instructions for your platform on pytorch.org.
After that please run the following command:
pip install -r requirements.txtRun:
python app.pyAnd go to the indicated local URL.
Install gradio_client and run the following Python code:
from pathlib import Path
import shutil
from gradio_client import Client, handle_file
client = Client("qchapp/3d-lungs-segmentation")
result_path = client.predict(
file_obj=handle_file("https://zenodo.org/record/8099852/files/lungs_ct.tif?download=1"),
api_name="/segment",
)
dest = Path("outputs/mask.tif")
dest.parent.mkdir(parents=True, exist_ok=True)
shutil.copy(result_path, dest)
print("Saved the mask in:", dest.resolve())If you are interested in the package used for segmentation please check the following GitHub repository!
