Neuro Lesion Inpainting Tool (neuroLIT) 🔥
Overview
This repository contains sourcecode and documentation related to our publication FastSurfer-LIT: Lesion Inpainting Tool for Whole Brain MRI Segmentation With Tumors, Cavities and Abnormalities. This tool can inpaint lesions independent of their shape or appearance for further downstream analysis. This allows subsequent analysis to run as if no lesion were present, enabling for example, FastSurfer's whole brain segmentation in cases with large brain tumors or surgical cavities. The extended documentation is located at DeepMI.org/neurolit. For integrated usage with FastSurfer see the FastSurfer documentation.
Quickstart
Docker / singularity
git clone https://github.com/Deep-MI/neurolit
cd neurolit
./neurolit/scripts/run_lit_containerized.sh --input_image T1w.nii.gz --lesion_mask lesion_mask.nii.gz --output_directory output_directory
# Add --singularity to use singularity instead of docker
Pip
pip install neurolit
lit-inpainting --input_image T1w.nii.gz --lesion_mask lesion_mask.nii.gz --output_directory output_directory
The command uses the recommended fast preset by default: DDIM with 50 inference steps and RePaint
10/15. Add --slow to restore the original 1000-step DDPM inference behavior.
When preparing a FastSurfer subject directory directly, add --fastsurfer_dir. This writes the
LIT outputs directly into the FastSurfer subject structure, including mri/inpainted.lit.nii.gz,
the processed mask at mri/mask.lit.nii.gz, and the original input mask at
mri/orig/mask.lit.nii.gz.
How to run neuroLIT
We recommend using containerization in combination with the neurolit/scripts/run_lit_containerized.sh wrapper script.
This will automatically pull the Docker image from Docker Hub or create a Singularity image cache and run the neuroLIT inpainting. Additional lit-inpainting flags such as --dilate 2 are forwarded through the wrapper to the container entrypoint.
If you do not pass --tag, the wrapper selects the newest numeric release tag available on Docker Hub (for example 0.7.1), rather than Docker's floating latest tag.
We also have a pip release of neuroLIT.
Running neuroLIT
The most straight forward way of doing the inpainting is just providing
- The T1w image
- The lesion mask
- An output directory
- (optional) The number times to dilate the lesion mask (default: 0)
./neurolit/scripts/run_lit_containerized.sh --input_image T1w.nii.gz --mask_image lesion_mask.nii.gz --output_directory output_directory --dilate 2
The default is to use Docker. Add the --singularity flag to use Singularity or Apptainer instead:
./neurolit/scripts/run_lit_containerized.sh --singularity --input_image T1w.nii.gz --mask_image lesion_mask.nii.gz --output_directory output_directory
On first use, the image is pulled from Docker Hub — no root required. The image is cached in containerization/deepmi_lit_<version>.sif and reused on subsequent runs.
If you already have a .sif file, pass it directly to skip the pull:
./neurolit/scripts/run_lit_containerized.sh --singularity_image /path/to/deepmi_lit.sif --input_image T1w.nii.gz --mask_image lesion_mask.nii.gz --output_directory output_directory
Both singularity and apptainer (the HPC-standard open-source fork) are supported automatically.
The outputs will be placed in the output directory in the folder inpainting_volumes and contain
- The inpainted T1w image (
inpainting_result.nii.gz) - The (dilated) mask used for inpainting in the same space as the input image (
inpainting_mask.nii.gz) - The conformed original image (
inpainting_original_image.nii.gz)
With --fastsurfer_dir, these outputs are integrated into the FastSurfer subject directory instead:
mri/inpainted.lit.nii.gzmri/mask.lit.nii.gzmri/orig/mask.lit.nii.gzmri/orig/inpainting_original_image.lit.nii.gzmri/orig/inpainting_masked_image.lit.nii.gzscripts/inpainting_*.lit.png
We recommend performing dilation, since undersegmentation can negatively impact the performance of the inpainting, while oversegmentation should not have significant impact.
Outside the effective lesion mask (including dilation), saved voxels exactly match the
conformed image. Conforming can change geometry and intensity scale; --keepgeom instead
preserves native geometry and outside-mask values, with generated values in native units.
Downstream segmentations and surfaces can still change outside the lesion.
Installation from PyPI
The same interface as above can be accessed from pypi:
# Install the package
pip install neurolit
# Download model checkpoints (recommended - download once, ~700MB)
lit-download-models
# Run neuroLIT
lit-inpainting --input_image T1w.nii.gz --lesion_mask lesion_mask.nii.gz --output_directory output_directory --dilate 2
Note: If you skip the lit-download-models step, models will be automatically downloaded on first use.
Expected Runtimes
Runtimes below are for a typical whole-brain T1w volume (1 mm isotropic), measured with neuroLIT v0.7.0:
| Hardware | Runtime |
|---|---|
| NVIDIA GeForce RTX 5070 Ti (16 GB) | ~17 minutes |
| Intel Xeon w5-2465X (CPU only) | ~5.5 hours |
GPU is strongly recommended for interactive use. CPU is feasible for batch/overnight processing.
Integration with FreeSurfer/FastSurfer
neuroLIT is integrated into FastSurfer for whole brain segmentation and cortical surface reconstruction of images with lesions and can be triggered with the --lesion_mask argument
For standalone usage with FreeSurfer/FastSurfer, neuroLIT provides post-processing scripts for integrating lesions into FastSurfer/FreeSurfer outputs. We recommend using the unified lit-postprocessing script which handles mapping the lesion mask to multiple segmentation files, running volume statistics (segstats), and performing surface masking.
Postprocessing
This script modifies FastSurfer/FreeSurfer segmentations and surface annotation files, and the corresponading statistics (.stats) files.
# Setup paths
export FASTSURFER_HOME=/path/to/FastSurfer
export FREESURFER_HOME=/path/to/freesurfer
source $FREESURFER_HOME/SetUpFreeSurfer.sh
# Run unified postprocessing
lit-postprocessing \
-sid SUBJECT_ID \
-sd /path/to/subjects_dir
Overview:
- Requirements: Automatically checks for FastSurfer/FreeSurfer installations using
$FASTSURFER_HOMEand$FREESURFER_HOME. FreeSurfer is required for surface postprocessing. - Dynamic Configuration: Uses
segstats_config.jsonfor volumetric stats andsurfstats_config.jsonfor surface stats. By default, all relevant FastSurfer annotation and segmentation files are modified. - Adjacent Label Reports: Generates adjacency reports for lesion segmentations, allowing users to assess which regions are affected or replaced by the lesion.
The current postprocessing workflow updates the primary FastSurfer outputs in place, keeps the
pre-lesion versions as .lit backups or mapped backup files, and writes lesion-specific reports
such as stats/aparc.DKTatlas+aseg.lesion_report.txt, stats/aseg.lesion_report.txt, and
stats/lesion_impact_summary.json.
CC statistics use stats/aseg.VINN.withCC.stats; legacy stats/aseg.auto.stats and
stats/aseg.auto.mgz remain aliases (or copies), preserving first pre-lesion backups.
Despite its .mgz suffix, the legacy statistics file contains text, not an MRI volume.
Training
The training script can be found here. The same docker image can be used for training, but you need to mount the training data directory using the -v flag. Note that training data are expected to be conformed (with the script conform.py).
Documentation
Comprehensive documentation is available in the doc/ directory and will be made public at DeepMI.org/neurolit.
Documentation includes:
- Installation guides
- Usage tutorials
- API reference
- Contributing guidelines
References
If you use neuroLIT for research publications, please cite:
Pollak C, Kuegler D, Bauer T, Rueber T, Reuter M, FastSurfer-LIT: Lesion Inpainting Tool for Whole Brain MRI Segmentation with Tumors, Cavities and Abnormalities, Imaging Neuroscience 2025. https://doi.org/10.1162/imag_a_00446
Metadata
Release files for neurolit 0.7.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| neurolit-0.7.1.tar.gz | 119.9 kB | Without provenance | Details for neurolit-0.7.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| neurolit-0.7.1-py3-none-any.whl | Python 3 | none | any | Details for neurolit-0.7.1-py3-none-any.whl |
Total release size: 251.6 kB
Release files / neurolit-0.7.1.tar.gz
| Download URL | neurolit-0.7.1.tar.gz |
|---|---|
| Size | 119.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
58f48437a576684990f381040dcf376ec2c8728a39a3105ad1cf73a89b601c8a
|
|
BLAKE2b-256 checksum How to use checksums |
8fa283731fa651849a01903d39bbcf04e8e9de31260b5665d0f72eae5bf9fb2e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.22
|
Release files / neurolit-0.7.1-py3-none-any.whl
| Download URL | neurolit-0.7.1-py3-none-any.whl |
|---|---|
| Size | 131.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aad63d2286a3ff1d89aa3ceb84fe40d9582bbdbc9fe3a569e8bc6f9c9d382155
|
|
BLAKE2b-256 checksum How to use checksums |
0787ae5e43da87d3e1d917b7a49ed01547a5c696409d47b44fed7eda5439e47a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.22
|
Security for neurolit 0.7.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.