syntx 0.1.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- syntx-0.1.7/PKG-INFO +160 -0
- syntx-0.1.7/README.md +140 -0
- syntx-0.1.7/pyproject.toml +39 -0
- syntx-0.1.7/setup.cfg +4 -0
- syntx-0.1.7/src/syntx/__init__.py +23 -0
- syntx-0.1.7/src/syntx/features.py +473 -0
- syntx-0.1.7/src/syntx/resnet.py +100 -0
- syntx-0.1.7/src/syntx/syn.py +1727 -0
- syntx-0.1.7/src/syntx/syn_jax.py +1412 -0
- syntx-0.1.7/src/syntx/transform.py +202 -0
- syntx-0.1.7/src/syntx.egg-info/PKG-INFO +160 -0
- syntx-0.1.7/src/syntx.egg-info/SOURCES.txt +20 -0
- syntx-0.1.7/src/syntx.egg-info/dependency_links.txt +1 -0
- syntx-0.1.7/src/syntx.egg-info/requires.txt +12 -0
- syntx-0.1.7/src/syntx.egg-info/top_level.txt +1 -0
- syntx-0.1.7/tests/test_coverage_helpers.py +513 -0
- syntx-0.1.7/tests/test_e2e_metrics.py +474 -0
- syntx-0.1.7/tests/test_feature_networks.py +281 -0
- syntx-0.1.7/tests/test_swin_unetr_empirical.py +128 -0
- syntx-0.1.7/tests/test_syn.py +322 -0
- syntx-0.1.7/tests/test_syn_jax.py +372 -0
- syntx-0.1.7/tests/test_transform.py +161 -0
syntx-0.1.7/PKG-INFO
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: syntx
|
|
3
|
+
Version: 0.1.7
|
|
4
|
+
Summary: Symmetric diffeomorphic and affine image registration methods in PyTorch and JAX
|
|
5
|
+
Author: syntx developers
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Requires-Python: >=3.8
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Requires-Dist: numpy
|
|
10
|
+
Requires-Dist: scipy
|
|
11
|
+
Requires-Dist: matplotlib
|
|
12
|
+
Requires-Dist: antspyx
|
|
13
|
+
Requires-Dist: torch
|
|
14
|
+
Requires-Dist: torchvision
|
|
15
|
+
Requires-Dist: jax
|
|
16
|
+
Requires-Dist: jaxlib
|
|
17
|
+
Provides-Extra: test
|
|
18
|
+
Requires-Dist: pytest; extra == "test"
|
|
19
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
20
|
+
|
|
21
|
+
# syntx
|
|
22
|
+
|
|
23
|
+
`syntx` is a high-performance Python package focusing on symmetric diffeomorphic (`SyN`) and affine image registration methods, built on top of **PyTorch** and **JAX** for GPU/MPS acceleration and auto-differentiation capabilities.
|
|
24
|
+
|
|
25
|
+
Ported from the registration modules of the `sulceye` package, `syntx` is designed for distribution on PyPI and works seamlessly with standard medical image types, particularly `ANTsImage` from the `antspyx` library.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
### ⚠️ Disclaimer & Differences from `ants.registration`
|
|
30
|
+
|
|
31
|
+
> [!IMPORTANT]
|
|
32
|
+
> **Validation Status**: The deep-learning feature-space similarity metrics (VGG19, DINOv2, Swin UNETR) in this repository are **experimental** and have **not** been deeply validated on large-scale clinical cohorts. They are intended strictly for research and exploration.
|
|
33
|
+
>
|
|
34
|
+
> **Key Differences from `ants.registration`:**
|
|
35
|
+
> 1. **GPU Acceleration**: Unlike standard `ants.registration` (which runs on CPU via ITK C++), Syntx supports **PyTorch and JAX** optimization backends for fast GPU/MPS execution.
|
|
36
|
+
> 2. **Optimizers**: Syntx uses Adam/Rprop for the affine stage and greedy composition steps scaling by ITK-style CFL (Courant-Friedrichs-Lewy) max voxel displacement bounds, while ANTs relies on C++ variants of L-BFGS or regularized gradient descent.
|
|
37
|
+
> 3. **Velocity-Field & Elastic Smoothing**: Separable Gaussian filters are implemented natively in JAX/PyTorch to perform fluid-like smoothing of update fields and elastic-like smoothing of composed fields, matching ITK's Gaussian regularization on the GPU.
|
|
38
|
+
> 4. **Multi-Resolution Pyramid**: Downsampling is performed dynamically using bilinear/trilinear grid interpolation in PyTorch/JAX to build image pyramids, rather than ITK's C++ downsampling filters.
|
|
39
|
+
> 5. **Feature-Space Metrics**: Similarity is evaluated on multi-scale feature representations (from vision transformers or CNNs) via zero-copy **DLPack** autograd sharing, rather than raw intensity maps.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Key Features
|
|
44
|
+
- **Auto-Differentiation Backends:** Choose between `'pytorch'` and `'jax'` for core computations.
|
|
45
|
+
- **Symmetric Normalization (SyN):** Fully symmetric greedy optimization matching classic ITK/ANTs SyN implementations.
|
|
46
|
+
- **Interoperability:** Seamless conversions between PyTorch/JAX coordinate spaces and ITK physical coordinate matrices.
|
|
47
|
+
- **Direct PyPy/PyPI Packaging:** Implemented cleanly with minimum external dependencies.
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
To install `syntx` locally from the repository:
|
|
54
|
+
```bash
|
|
55
|
+
pip install -e .
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Dependencies
|
|
59
|
+
- `numpy`
|
|
60
|
+
- `scipy`
|
|
61
|
+
- `matplotlib`
|
|
62
|
+
- `antspyx`
|
|
63
|
+
- `torch`
|
|
64
|
+
- `jax`
|
|
65
|
+
- `jaxlib`
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Usage Example
|
|
70
|
+
|
|
71
|
+
`syntx` exposes a high-level `syn` and `registration` API that mirrors `ants.registration`:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import ants
|
|
75
|
+
import syntx
|
|
76
|
+
|
|
77
|
+
# Load ANTs images
|
|
78
|
+
fixed = ants.image_read( ants.get_data('r16') )
|
|
79
|
+
moving = ants.image_read( ants.get_data('r64') )
|
|
80
|
+
|
|
81
|
+
# Run registration using PyTorch (default)
|
|
82
|
+
result = syntx.syn(
|
|
83
|
+
fixed=fixed,
|
|
84
|
+
moving=moving,
|
|
85
|
+
type_of_transform='SyNTo',
|
|
86
|
+
backend='pytorch',
|
|
87
|
+
reg_iterations=[100, 100, 50],
|
|
88
|
+
affine_iterations=[100, 50, 20],
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
# Access the warped moving output image
|
|
92
|
+
warped_moving = result['warpedmovout']
|
|
93
|
+
|
|
94
|
+
# Access transform files (saved to temporary paths for ANTs compatibility)
|
|
95
|
+
forward_transforms = result['fwdtransforms']
|
|
96
|
+
inverse_transforms = result['invtransforms']
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
For JAX backend acceleration:
|
|
100
|
+
```python
|
|
101
|
+
result = syntx.syn(
|
|
102
|
+
fixed=fixed,
|
|
103
|
+
moving=moving,
|
|
104
|
+
type_of_transform='SyNTo',
|
|
105
|
+
backend='jax',
|
|
106
|
+
reg_iterations=[100, 100, 50],
|
|
107
|
+
affine_iterations=[100, 50, 20],
|
|
108
|
+
)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Running the Examples and Generating Reports
|
|
114
|
+
|
|
115
|
+
An example comparing classic ANTs, PyTorch, and JAX registration is included under `examples/`. It generates a comparison report summarizing Mutual Information, Jacobian Determinants (topological safety), and Execution Speed.
|
|
116
|
+
|
|
117
|
+
To run the comparison:
|
|
118
|
+
```bash
|
|
119
|
+
python examples/generate_ants_2d_comparison_report.py
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
This generates an HTML report under `reports/ants_2d_syn_comparison.html`.
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Running Tests
|
|
127
|
+
|
|
128
|
+
Tests can be executed via `pytest`:
|
|
129
|
+
```bash
|
|
130
|
+
pytest
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Makefile Automation
|
|
136
|
+
|
|
137
|
+
A `Makefile` is included to automate standard development tasks:
|
|
138
|
+
|
|
139
|
+
* **Install** (install package in editable mode):
|
|
140
|
+
```bash
|
|
141
|
+
make install
|
|
142
|
+
```
|
|
143
|
+
* **Test** (run test suite in Fast mode, skipping slow 3D registrations, and printing a code coverage table):
|
|
144
|
+
```bash
|
|
145
|
+
make test
|
|
146
|
+
```
|
|
147
|
+
* **Test All** (run the full test suite including slow 3D registrations, with coverage):
|
|
148
|
+
```bash
|
|
149
|
+
make test-all
|
|
150
|
+
```
|
|
151
|
+
* **Clean** (remove build artifacts, cached directories, and temporary files):
|
|
152
|
+
```bash
|
|
153
|
+
make clean
|
|
154
|
+
```
|
|
155
|
+
* **Release** (clean, build sdist and wheel packages, and upload to PyPI using twine):
|
|
156
|
+
```bash
|
|
157
|
+
make release
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
It automatically detects and prioritizes the active python virtual environment (`VIRTUAL_ENV`).
|
syntx-0.1.7/README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# syntx
|
|
2
|
+
|
|
3
|
+
`syntx` is a high-performance Python package focusing on symmetric diffeomorphic (`SyN`) and affine image registration methods, built on top of **PyTorch** and **JAX** for GPU/MPS acceleration and auto-differentiation capabilities.
|
|
4
|
+
|
|
5
|
+
Ported from the registration modules of the `sulceye` package, `syntx` is designed for distribution on PyPI and works seamlessly with standard medical image types, particularly `ANTsImage` from the `antspyx` library.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
### ⚠️ Disclaimer & Differences from `ants.registration`
|
|
10
|
+
|
|
11
|
+
> [!IMPORTANT]
|
|
12
|
+
> **Validation Status**: The deep-learning feature-space similarity metrics (VGG19, DINOv2, Swin UNETR) in this repository are **experimental** and have **not** been deeply validated on large-scale clinical cohorts. They are intended strictly for research and exploration.
|
|
13
|
+
>
|
|
14
|
+
> **Key Differences from `ants.registration`:**
|
|
15
|
+
> 1. **GPU Acceleration**: Unlike standard `ants.registration` (which runs on CPU via ITK C++), Syntx supports **PyTorch and JAX** optimization backends for fast GPU/MPS execution.
|
|
16
|
+
> 2. **Optimizers**: Syntx uses Adam/Rprop for the affine stage and greedy composition steps scaling by ITK-style CFL (Courant-Friedrichs-Lewy) max voxel displacement bounds, while ANTs relies on C++ variants of L-BFGS or regularized gradient descent.
|
|
17
|
+
> 3. **Velocity-Field & Elastic Smoothing**: Separable Gaussian filters are implemented natively in JAX/PyTorch to perform fluid-like smoothing of update fields and elastic-like smoothing of composed fields, matching ITK's Gaussian regularization on the GPU.
|
|
18
|
+
> 4. **Multi-Resolution Pyramid**: Downsampling is performed dynamically using bilinear/trilinear grid interpolation in PyTorch/JAX to build image pyramids, rather than ITK's C++ downsampling filters.
|
|
19
|
+
> 5. **Feature-Space Metrics**: Similarity is evaluated on multi-scale feature representations (from vision transformers or CNNs) via zero-copy **DLPack** autograd sharing, rather than raw intensity maps.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Key Features
|
|
24
|
+
- **Auto-Differentiation Backends:** Choose between `'pytorch'` and `'jax'` for core computations.
|
|
25
|
+
- **Symmetric Normalization (SyN):** Fully symmetric greedy optimization matching classic ITK/ANTs SyN implementations.
|
|
26
|
+
- **Interoperability:** Seamless conversions between PyTorch/JAX coordinate spaces and ITK physical coordinate matrices.
|
|
27
|
+
- **Direct PyPy/PyPI Packaging:** Implemented cleanly with minimum external dependencies.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
To install `syntx` locally from the repository:
|
|
34
|
+
```bash
|
|
35
|
+
pip install -e .
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Dependencies
|
|
39
|
+
- `numpy`
|
|
40
|
+
- `scipy`
|
|
41
|
+
- `matplotlib`
|
|
42
|
+
- `antspyx`
|
|
43
|
+
- `torch`
|
|
44
|
+
- `jax`
|
|
45
|
+
- `jaxlib`
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Usage Example
|
|
50
|
+
|
|
51
|
+
`syntx` exposes a high-level `syn` and `registration` API that mirrors `ants.registration`:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
import ants
|
|
55
|
+
import syntx
|
|
56
|
+
|
|
57
|
+
# Load ANTs images
|
|
58
|
+
fixed = ants.image_read( ants.get_data('r16') )
|
|
59
|
+
moving = ants.image_read( ants.get_data('r64') )
|
|
60
|
+
|
|
61
|
+
# Run registration using PyTorch (default)
|
|
62
|
+
result = syntx.syn(
|
|
63
|
+
fixed=fixed,
|
|
64
|
+
moving=moving,
|
|
65
|
+
type_of_transform='SyNTo',
|
|
66
|
+
backend='pytorch',
|
|
67
|
+
reg_iterations=[100, 100, 50],
|
|
68
|
+
affine_iterations=[100, 50, 20],
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
# Access the warped moving output image
|
|
72
|
+
warped_moving = result['warpedmovout']
|
|
73
|
+
|
|
74
|
+
# Access transform files (saved to temporary paths for ANTs compatibility)
|
|
75
|
+
forward_transforms = result['fwdtransforms']
|
|
76
|
+
inverse_transforms = result['invtransforms']
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
For JAX backend acceleration:
|
|
80
|
+
```python
|
|
81
|
+
result = syntx.syn(
|
|
82
|
+
fixed=fixed,
|
|
83
|
+
moving=moving,
|
|
84
|
+
type_of_transform='SyNTo',
|
|
85
|
+
backend='jax',
|
|
86
|
+
reg_iterations=[100, 100, 50],
|
|
87
|
+
affine_iterations=[100, 50, 20],
|
|
88
|
+
)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Running the Examples and Generating Reports
|
|
94
|
+
|
|
95
|
+
An example comparing classic ANTs, PyTorch, and JAX registration is included under `examples/`. It generates a comparison report summarizing Mutual Information, Jacobian Determinants (topological safety), and Execution Speed.
|
|
96
|
+
|
|
97
|
+
To run the comparison:
|
|
98
|
+
```bash
|
|
99
|
+
python examples/generate_ants_2d_comparison_report.py
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
This generates an HTML report under `reports/ants_2d_syn_comparison.html`.
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Running Tests
|
|
107
|
+
|
|
108
|
+
Tests can be executed via `pytest`:
|
|
109
|
+
```bash
|
|
110
|
+
pytest
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Makefile Automation
|
|
116
|
+
|
|
117
|
+
A `Makefile` is included to automate standard development tasks:
|
|
118
|
+
|
|
119
|
+
* **Install** (install package in editable mode):
|
|
120
|
+
```bash
|
|
121
|
+
make install
|
|
122
|
+
```
|
|
123
|
+
* **Test** (run test suite in Fast mode, skipping slow 3D registrations, and printing a code coverage table):
|
|
124
|
+
```bash
|
|
125
|
+
make test
|
|
126
|
+
```
|
|
127
|
+
* **Test All** (run the full test suite including slow 3D registrations, with coverage):
|
|
128
|
+
```bash
|
|
129
|
+
make test-all
|
|
130
|
+
```
|
|
131
|
+
* **Clean** (remove build artifacts, cached directories, and temporary files):
|
|
132
|
+
```bash
|
|
133
|
+
make clean
|
|
134
|
+
```
|
|
135
|
+
* **Release** (clean, build sdist and wheel packages, and upload to PyPI using twine):
|
|
136
|
+
```bash
|
|
137
|
+
make release
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
It automatically detects and prioritizes the active python virtual environment (`VIRTUAL_ENV`).
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "syntx"
|
|
7
|
+
version = "0.1.7"
|
|
8
|
+
description = "Symmetric diffeomorphic and affine image registration methods in PyTorch and JAX"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = {text = "Apache-2.0"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "syntx developers"}
|
|
14
|
+
]
|
|
15
|
+
dependencies = [
|
|
16
|
+
"numpy",
|
|
17
|
+
"scipy",
|
|
18
|
+
"matplotlib",
|
|
19
|
+
"antspyx",
|
|
20
|
+
"torch",
|
|
21
|
+
"torchvision",
|
|
22
|
+
"jax",
|
|
23
|
+
"jaxlib"
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.optional-dependencies]
|
|
27
|
+
test = [
|
|
28
|
+
"pytest",
|
|
29
|
+
"pytest-cov"
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[tool.setuptools.packages.find]
|
|
33
|
+
where = ["src"]
|
|
34
|
+
include = ["syntx*"]
|
|
35
|
+
|
|
36
|
+
[tool.pytest.ini_options]
|
|
37
|
+
testpaths = ["tests"]
|
|
38
|
+
python_files = ["test_*.py"]
|
|
39
|
+
addopts = "--cov=syntx --cov-report=term-missing"
|
syntx-0.1.7/setup.cfg
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from .syn import registration, SyNTo
|
|
2
|
+
from .syn_jax import SyNTo as SyNToJax
|
|
3
|
+
from .transform import SyNToTransform
|
|
4
|
+
from .features import FeatureSpaceLoss, VGG19Extractor, DINOv2Extractor, ResNet10Extractor, SwinUNETRExtractor
|
|
5
|
+
|
|
6
|
+
# Expose both syn and registration to satisfy user requirements
|
|
7
|
+
syn = registration
|
|
8
|
+
|
|
9
|
+
__version__ = "0.1.7"
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"syn",
|
|
14
|
+
"registration",
|
|
15
|
+
"SyNTo",
|
|
16
|
+
"SyNToJax",
|
|
17
|
+
"SyNToTransform",
|
|
18
|
+
"FeatureSpaceLoss",
|
|
19
|
+
"VGG19Extractor",
|
|
20
|
+
"DINOv2Extractor",
|
|
21
|
+
"ResNet10Extractor",
|
|
22
|
+
"SwinUNETRExtractor",
|
|
23
|
+
]
|