Metadata-Version: 2.4
Name: neuromodex-vnet-dbs
Version: 0.2.2
Summary: NeuroModex VNet DBS: segmentation and conductivity mapping utilities
Project-URL: Homepage, https://github.com/
Author-email: "FHNW (Michel Ruchti)" <michel.ruchti@fhnw.ch>
License: MIT License
        
        Copyright (c) 2025 Fachhochschule Nordwestschweiz (Michel Ruchti)
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: DBS,VNet,deep-learning,medical-imaging,segmentation
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Requires-Python: >=3.9
Requires-Dist: numpy>=2.3.5
Requires-Dist: scipy>=1.16.1
Requires-Dist: simpleitk>=2.5.3
Requires-Dist: torch>=2.9.1
Description-Content-Type: text/markdown

Neuromodex VNet DBS
====================

Deep‑learning utilities for DBS workflows, including MRI brain tissue segmentation (VNet) and conductivity mapping. This
repository provides a Python package and optional 3D Slicer modules to integrate the models into imaging workflows.

Note: This project is still under development.


Features
--------

- VNet‑based multi‑class brain tissue segmentation
- Conductivity mapping utilities
- Pre/post‑processing
- PyTorch inference with automatic device selection (CPU/GPU)
- 3D Slicer plugin scaffolding for GUI‑based use
- The segmentation model was trained using labels generated with **ELMA**, a semi‑automatic DBS tissue
  classification/segmentation tool (commonly used to classify tissues such as grey matter, white matter, blood, and CSF
  for patient‑specific DBS FEM modeling
  workflows). [[1]](https://liu.se/en/article/ne-downloads) [[2]](https://pubmed.ncbi.nlm.nih.gov/36086324/)

Installation
------------
Requirements: Python 3.9+

```
pip install neuromodex-vnet-dbs
```

The wheel bundles the `neuromodex_vnet_dbs/weights/` directory so the packaged models can load without any extra
downloads.

Quick start Segmentation
-----------
*Note that the input image must be skull stripped and preferably N4 bias corrected. Good choices are HD_BET and
SimpleITK's N4BiasFieldCorrection.*


```python
import SimpleITK as sitk
from neuromodex_vnet_dbs import SegmentationPipeline

# Load an input image (e.g., NIfTI)
img = sitk.ReadImage("/path/to/volume.nii.gz")
# or
img = "path/to/volume.nii.gz"

# Run the segmentation pipeline
pipe = SegmentationPipeline(img)  # pass either as string or sitk volume
result = pipe.segment_fast(img)  # ~7 seconds

# or this for clearer csf segmentation
result = pipe.segment_gmm_csf(img)  # ~1.5 minutes

# The returned object is the segmented image
```
You can also use the `segment_vnet` function to segment a volume with a single command: 

```python
from neuromodex_vnet_dbs.easy_segment import segment_vnet

segmented = segment_vnet("path/to/mri_image.nii.gz")
```

Quick Start Conductivity Mapping
-----------

```python
import SimpleITK as sitk
from neuromodex_vnet_dbs import ConductivityProcessingPipeline

mri_img = sitk.ReadImage("path/to/mri_image.nii.gz")
seg_img = sitk.ReadImage("path/to/seg_image.nii.gz")

pipe = ConductivityProcessingPipeline(seg_img, mri_img)
result = pipe.run()
```

Or use the easy wrapper:

```python
from neuromodex_vnet_dbs.easy_conductivity_mapping import map_conductivities

conductivities = map_conductivities("path/to/mri_image.nii.gz", "path/to/seg_image.nii.gz")
```

3D Slicer integration
--------------------------------
This repo includes helper scripts and example module folders under `slicer/`.
These scripts can also be used as CLI tools.

- To install one or more module folders into your local Slicer profile, run either:

```python
from neuromodex_vnet_dbs.slicer import interactive_installation

interactive_installation()
```

or

```
python neuromodex_vnet_dbs/slicer/slicer_install_plugin.py
```

Follow the prompts to choose the plugin(s) and target Slicer installation. Restart Slicer afterwards.

The plugins can then be found in Segmentation/BrainSegmentation and Electrical Conductivity/ConductivityMapping.

Note: The first execution in slicer will take a few minutes to download all the required data.

License
-------
This project is licensed under the terms of the MIT License. See the `LICENSE` file for details.

Citation
--------
If you use this project in your research, please cite the appropriate papers for VNet and any downstream methods you
apply.
