A toolkit for precise segmentation of tumors in PET/CT scans.
Project description
LION
Fully automated tumor segmentation for FDG and PSMA PET scans
Quick Start
python -m venv lion-env
source lion-env/bin/activate # macOS / Linux
lion-env\Scripts\activate # Windows
pip install git+https://github.com/ENHANCE-PET/LION.git
lionz -d /path/to/data -m fdg
That's it. Models download automatically on first run.
Requirements
- Python 3.10+
- 32GB RAM recommended
- GPU optional (NVIDIA CUDA or Apple Silicon MPS) - CPU works but slower
Installation
We recommend installing LION in a virtual environment to avoid dependency conflicts.
Using uv (recommended)
uv is a fast Python package manager that handles virtual environments automatically.
# Install uv if you don't have it
curl -LsSf https://astral.sh/uv/install.sh | sh # macOS/Linux
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" # Windows
Install from GitHub:
uv venv lion-env
# Activate the environment
source lion-env/bin/activate # macOS / Linux
lion-env\Scripts\activate # Windows
uv pip install git+https://github.com/ENHANCE-PET/LION.git
Install from source:
git clone https://github.com/ENHANCE-PET/LION.git
cd LION
uv sync
Using pip + venv
python -m venv lion-env
# Activate the environment
source lion-env/bin/activate # macOS / Linux
lion-env\Scripts\activate # Windows
pip install git+https://github.com/ENHANCE-PET/LION.git
Input Data Structure
data/
├── patient_001/
│ └── PT_scan.nii.gz # PET file with PT_ prefix
├── patient_002/
│ └── PT_scan.nii.gz
└── patient_003/
├── PT_scan.nii.gz
└── CT_scan.nii.gz # CT optional, needs CT_ prefix
Rules:
- One folder per subject
- PET files must start with
PT_ - CT files must start with
CT_(optional) - Supports
.niiand.nii.gz - DICOM folders also supported (modality auto-detected from tags)
Messy Data?
Use the lion-mcp server with Claude Code or Codex to organize chaotic DICOM/NIfTI dumps. See lion-mcp/README.md.
CLI Usage
# Basic
lionz -d /path/to/data -m fdg
# With SUV threshold
lionz -d /path/to/data -m fdg -t 2.5
# Generate MIP preview
lionz -d /path/to/data -m fdg -g
# Parallel processing (multiple subjects)
lionz -d /path/to/data -m fdg -p 4
# All options
lionz -d /path/to/data -m fdg -t 2.5 -g -p 4
Options:
| Flag | Description |
|---|---|
-d |
Input directory containing subject folders |
-m |
Model name: fdg or psma |
-t |
SUV threshold (requires SUV-calibrated input) |
-g |
Generate rotational MIP GIF |
-p |
Number of parallel jobs |
-h |
Show help |
Library Usage
import lionz
# From file path
result = lionz.lion('/path/to/PT_scan.nii.gz', 'fdg')
# From SimpleITK image
import SimpleITK as sitk
img = sitk.ReadImage('/path/to/PT_scan.nii.gz')
seg = lionz.lion(img, 'fdg') # Returns SimpleITK.Image
# From numpy array
import numpy as np
array = np.load('pet_data.npy')
spacing = (2.0, 2.0, 2.0)
seg = lionz.lion((array, spacing), 'fdg') # Returns np.ndarray
# With options
result = lionz.lion(
'/path/to/scan.nii.gz',
'fdg',
output_dir='/path/to/output',
accelerator='mps', # 'cpu', 'cuda', or 'mps'
threshold=2.5
)
Important: Wrap in if __name__ == '__main__': to avoid multiprocessing issues:
import lionz
if __name__ == '__main__':
lionz.lion('/path/to/scan.nii.gz', 'fdg')
Models
| Tracer | Model | Training Data | Status |
|---|---|---|---|
| FDG | fdg |
5,235 patients | Stable |
| PSMA | psma |
2,046 patients | Stable |
Output Structure
patient_001/
├── PT_scan.nii.gz # Original input
└── lionz-2024-01-15-10-30-00/
├── segmentations/
│ ├── PT_scan_tumor_seg.nii.gz # Tumor mask
│ └── patient_001_rotational_mip.gif # If -g flag used
└── stats/
└── patient_001_metrics.csv # Volume, SUV metrics
Platform Support
| Platform | Accelerator | Status |
|---|---|---|
| Linux | CUDA | Fully supported |
| Linux | CPU | Supported (slower) |
| macOS (Apple Silicon) | MPS | Fully supported |
| macOS (Intel) | CPU | Supported (slower) |
| Windows | CUDA | Fully supported |
| Windows | CPU | Supported (slower) |
For AI Agents
LION provides an MCP server for organizing messy medical imaging data. Install and configure:
cd lion-mcp && pip install -e .
Add to .mcp.json:
{
"lion-mcp": {
"type": "stdio",
"command": ".venv/bin/lion-mcp"
}
}
Available MCP tools:
scan_directory- Scan for DICOM/NIfTI files, extract metadataread_dicom_header- Read full DICOM tagsorganize_for_lion- Reorganize files into LION structurevalidate_structure- Check if directory is LION-readyget_lion_requirements- Get structure documentation
Telemetry
LION collects anonymous usage statistics to help us understand how the tool is used and prioritize development. This is completely optional.
What we collect: version, model used, platform, accelerator type, number of subjects, success/failure
What we DON'T collect: file paths, patient data, IP addresses, any identifiable information
Opt-out:
export LIONZ_TELEMETRY=0
Citation
DOI: 10.5281/zenodo.12626789
License
Apache 2.0. For enterprise integrations, contact Zenta.
Contributors
Part of the ENHANCE.PET initiative.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lionz-1.0.4.tar.gz.
File metadata
- Download URL: lionz-1.0.4.tar.gz
- Upload date:
- Size: 42.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ac9117c138397b07eed713c1721c95ce2842bee85c285913ac9058db7e9a3e6
|
|
| MD5 |
901e1fabdd830b4797949f18393a6b1b
|
|
| BLAKE2b-256 |
cac363690d4543396a5072c500abb934b565e62a71c2779881b5d4fc279a515c
|
File details
Details for the file lionz-1.0.4-py3-none-any.whl.
File metadata
- Download URL: lionz-1.0.4-py3-none-any.whl
- Upload date:
- Size: 45.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c69df75273df718d9ba04814da659f7a8b14fd5f0e700b680d5cd53481c9f7e
|
|
| MD5 |
e2976e5bfedcb8eb6e2340fdc200b981
|
|
| BLAKE2b-256 |
a779a194566457608f94e9eb8589edbb1b800356be74ebab4f51e8ae75d5603e
|