Metadata-Version: 2.4
Name: nifti_dynamic
Version: 0.2.0
Summary: A package for dynamic NIFTI analysis
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: numpy
Requires-Dist: nibabel
Requires-Dist: indexed_gzip
Requires-Dist: scipy
Requires-Dist: scikit-learn
Requires-Dist: tqdm
Requires-Dist: ipython>=8.12.3
Requires-Dist: scikit-image>=0.21.0
Requires-Dist: matplotlib>=3.7.5
Requires-Dist: pandas>=2.0.3
Requires-Dist: opencv-python>=4.12.0.88
Requires-Dist: rich
Requires-Dist: typer
Requires-Dist: torch>=2.5.1

![Banner](banner.jpg)

# nifti_dynamic 🧠⚡

Efficient TAC extraction and Patlak analysis of HUGE PET arrays in NIfTI format. Works with gzipped 4D PET images (saving 90% disk space vs DICOM) 📦. All algorithms load partial chunks to prevent memory crashes when handling massive arrays (440×440×645×69×4 bytes = 32GB).

> Implementation based on Andersen TL, et al. *Diagnostics* 2024;14(15):1590. [doi:10.3390/diagnostics14151590](https://doi.org/10.3390/diagnostics14151590)

## Installation 💾

```bash
pip install nifti_dynamic
```

**Important**: Always ensure `indexed_gzip` is installed for significantly faster reading of gzipped NIfTI arrays (.nii.gz) ⚡

## Performance ⏱️

- Automatic extraction of 4 VOIs: 30 seconds
- TAC for single organs: 10 seconds  
- TACs for all 114 TotalSegmentator organs: 10 minutes
- Full voxel Patlak for 440×440×645×69 array: 30 seconds

## CLI Usage 🚀

### Extract Input Function from Aorta

```bash
extract_input_function \
  --pet dpet.nii.gz \
  --totalseg totalseg.nii.gz \
  --output ./results
```

### Extract TACs for All Organs

```bash
extract_tacs \
  --pet dpet.nii.gz \
  --segmentation totalseg.nii.gz \
  --output ./tacs
```

### Voxel-wise Patlak Analysis

```bash
voxel_patlak \
  --pet dpet.nii.gz \
  --input-function input_fun.csv \
  --output ./patlak
```

### Downsample Dynamic PET (2x)

```bash
resample_pet \
  --pet dpet.nii.gz \
  --output dpet_2x.nii.gz
```

## Python API Usage

For programmatic access, see [example.py](example.py) for detailed Python API usage.


