Metadata-Version: 2.1
Name: TPTBox
Version: 0.0.2
Summary: A Torso Processing Toolbox capable of processing BIDS-compatible datasets, singular niftys, points of interests, segmentations, and much more.
Home-page: https://github.com/Hendrik-code/TPTBox
License: GNU AFFERO GENERAL PUBLIC LICENSE v3.0, 19 November 2007
Author: Robert Graf
Author-email: robert.graf@tum.de
Requires-Python: >=3.10,<4.0
Classifier: License :: Other/Proprietary License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Dist: SimpleITK (>=2.3.1,<3.0.0)
Requires-Dist: connected-components-3d (>=3.12.3,<4.0.0)
Requires-Dist: dataclasses
Requires-Dist: dicom2nifti
Requires-Dist: dill (>=0.3.7,<0.4.0)
Requires-Dist: fill-voids (>=2.0.6,<3.0.0)
Requires-Dist: func-timeout (>=4.3.5,<5.0.0)
Requires-Dist: matplotlib (>=3.8.2,<4.0.0)
Requires-Dist: nibabel (>=5.2.0,<6.0.0)
Requires-Dist: numpy (>=1.26.3,<2.0.0)
Requires-Dist: pathlib
Requires-Dist: pytest (>=7.4.4,<8.0.0)
Requires-Dist: pyvista (>=0.43.2,<0.44.0)
Requires-Dist: scikit-image (>=0.22.0,<0.23.0)
Requires-Dist: scipy (>=1.12.0,<2.0.0)
Requires-Dist: typing-extensions (>=4.9.0,<5.0.0)
Project-URL: Repository, https://github.com/Hendrik-code/TPTBox
Description-Content-Type: text/markdown

[![PyPI version tptbox](https://badge.fury.io/py/tptbox.svg)](https://pypi.python.org/pypi/tptbox/)

# Torso Processing ToolBox (TPTBox)

This is a multi-functional package to handle any sort of bids-conform dataset (CT, MRI, ...)
It can find, filter, search any BIDS_Family and subjects, and has many functionalities, among them:
- Easily loop over datasets, and the required files
- Read, Write Niftys, centroid jsons, ...
- Reorient, Resample, Shift Niftys, Centroids, labels
- Modular 2D snapshot generation (different views, MIPs, ...)
- 3D Mesh generation from segmentation and snapshots from them
- Running the Anduin docker smartly
- Registration
- Logging everything consistently
- ...

## Install the package
#### Make venv:
```
conda create -n 3.10 python=3.10 
conda activate 3.10
```
### One of the following:
(you should be in the project folder)
```
pip install -e ./
```
or:

Develop mode is really, really nice:
```
python setup.py develop
sudo python3 setup.py develop
```

If "python3" don't know where to install, use
```
which python
sudo <result from which python> setup.py develop
```


## Functionalities

Each folder in this package represents a different functionality.

The top-level-hierarchy incorporates the most important files, the BIDS_files.

### BIDS_Files

This file builds a data model out of the BIDS file names.
It can load a dataset as a BIDS_Global_info file, from which search queries and loops over the dataset can be started.
See ```tutorial_BIDS_files.ipynb``` for details.

### bids_constants
Defines constants for the BIDS nomenclature (sequence-splitting keys, naming conventions...)

### vert_constants

Contains definitions and sort order for our intern labels, for vertebrae, POI, ...

### Rotation and Resampling

Example rotate and resample.

```python
# R right, L left .. {"S": "ax", "I": "ax", "L": "sag", "R": "sag", "A": "cor", "P": "cor"}
img_rot = reorient_to(img, axcodes_to=("P", "I", "R")) 
img_rot_iso = resample_nib(img_rot, voxel_spacing=(1, 1, 1), order=3, c_val=0)
```

### Snapshot2D

The snapshot function automatically generates sag, cor, axial cuts in the center of a segmentation.

```python
from pathlib import Path
from BIDS.wrapper.snapshot_mr_fun2 import Snapshot_Frame,create_snapshot
ct = Path('Path to CT')
mri = Path('Path to MRI')
vert = Path('Path to Vertebra segmentation')
subreg = Path('Path to Vertebra subregions')
cdt = (vert,subreg,[50]) # 50 is subregion of the vertebra body
# cdt can be also loaded as a json. See definition Centroid_DictList in nii_utils

ct_frame = Snapshot_Frame(image=ct, segmentation=vert, centroids=cdt, mode="CT", coronal=True, axial=True)
mr_frame = Snapshot_Frame(image=mri, segmentation=vert, centroids=None, mode="MRI", coronal=True, axial=True)
create_snapshot(snp_path='snapshot.jpg',frames=[ct_frame, mr_frame])
```


### Snapshot3D

```python
TBD
```

### Docker

```python
TBD
```

### Logger

```python
TBD
```
