neuroreg 0.1.0__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.
Files changed (53) hide show
  1. neuroreg-0.1.0/LICENSE +21 -0
  2. neuroreg-0.1.0/PKG-INFO +510 -0
  3. neuroreg-0.1.0/README.md +421 -0
  4. neuroreg-0.1.0/neuroreg/__init__.py +22 -0
  5. neuroreg-0.1.0/neuroreg/_sys_info.py +108 -0
  6. neuroreg-0.1.0/neuroreg/_version.py +5 -0
  7. neuroreg-0.1.0/neuroreg/bbreg/__init__.py +27 -0
  8. neuroreg-0.1.0/neuroreg/bbreg/cost.py +128 -0
  9. neuroreg-0.1.0/neuroreg/bbreg/io.py +231 -0
  10. neuroreg-0.1.0/neuroreg/bbreg/optimize.py +566 -0
  11. neuroreg-0.1.0/neuroreg/bbreg/projection.py +206 -0
  12. neuroreg-0.1.0/neuroreg/bbreg/register.py +378 -0
  13. neuroreg-0.1.0/neuroreg/bbreg/sampling.py +303 -0
  14. neuroreg-0.1.0/neuroreg/cli/__init__.py +9 -0
  15. neuroreg-0.1.0/neuroreg/cli/bbreg.py +371 -0
  16. neuroreg-0.1.0/neuroreg/cli/coreg.py +169 -0
  17. neuroreg-0.1.0/neuroreg/cli/lta.py +281 -0
  18. neuroreg-0.1.0/neuroreg/cli/robreg.py +181 -0
  19. neuroreg-0.1.0/neuroreg/cli/sys_info.py +34 -0
  20. neuroreg-0.1.0/neuroreg/image/__init__.py +21 -0
  21. neuroreg-0.1.0/neuroreg/image/centroid.py +45 -0
  22. neuroreg-0.1.0/neuroreg/image/map.py +267 -0
  23. neuroreg-0.1.0/neuroreg/image/pyramid.py +217 -0
  24. neuroreg-0.1.0/neuroreg/image/segmentation.py +717 -0
  25. neuroreg-0.1.0/neuroreg/image/smooth.py +105 -0
  26. neuroreg-0.1.0/neuroreg/imreg/__init__.py +7 -0
  27. neuroreg-0.1.0/neuroreg/imreg/coreg.py +546 -0
  28. neuroreg-0.1.0/neuroreg/imreg/init.py +73 -0
  29. neuroreg-0.1.0/neuroreg/imreg/irls.py +613 -0
  30. neuroreg-0.1.0/neuroreg/imreg/losses.py +266 -0
  31. neuroreg-0.1.0/neuroreg/imreg/optimize.py +225 -0
  32. neuroreg-0.1.0/neuroreg/imreg/reg_model.py +503 -0
  33. neuroreg-0.1.0/neuroreg/imreg/robreg.py +470 -0
  34. neuroreg-0.1.0/neuroreg/imreg/robust.py +259 -0
  35. neuroreg-0.1.0/neuroreg/transforms/__init__.py +51 -0
  36. neuroreg-0.1.0/neuroreg/transforms/lta.py +512 -0
  37. neuroreg-0.1.0/neuroreg/transforms/matrices.py +679 -0
  38. neuroreg-0.1.0/neuroreg/transforms/metrics.py +328 -0
  39. neuroreg-0.1.0/neuroreg.egg-info/PKG-INFO +510 -0
  40. neuroreg-0.1.0/neuroreg.egg-info/SOURCES.txt +51 -0
  41. neuroreg-0.1.0/neuroreg.egg-info/dependency_links.txt +1 -0
  42. neuroreg-0.1.0/neuroreg.egg-info/entry_points.txt +6 -0
  43. neuroreg-0.1.0/neuroreg.egg-info/requires.txt +47 -0
  44. neuroreg-0.1.0/neuroreg.egg-info/top_level.txt +1 -0
  45. neuroreg-0.1.0/pyproject.toml +163 -0
  46. neuroreg-0.1.0/setup.cfg +4 -0
  47. neuroreg-0.1.0/tests/test_bbreg.py +312 -0
  48. neuroreg-0.1.0/tests/test_cli.py +181 -0
  49. neuroreg-0.1.0/tests/test_coreg.py +503 -0
  50. neuroreg-0.1.0/tests/test_irls.py +290 -0
  51. neuroreg-0.1.0/tests/test_lta_diff.py +397 -0
  52. neuroreg-0.1.0/tests/test_robreg.py +68 -0
  53. neuroreg-0.1.0/tests/test_robust_weights.py +132 -0
neuroreg-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Deep Medical Imaging Lab (PI Reuter)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,510 @@
1
+ Metadata-Version: 2.4
2
+ Name: neuroreg
3
+ Version: 0.1.0
4
+ Summary: A package for 3D neuroimaging registration with PyTorch.
5
+ Author: Martin Reuter
6
+ Maintainer: Martin Reuter
7
+ License: MIT License
8
+
9
+ Copyright (c) 2020 Deep Medical Imaging Lab (PI Reuter)
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ Project-URL: homepage, https://Deep-MI.github.io/neuroreg/dev/index.html
30
+ Project-URL: documentation, https://Deep-MI.github.io/neuroreg/dev/index.html
31
+ Project-URL: source, https://github.com/Deep-MI/neuroreg
32
+ Project-URL: tracker, https://github.com/Deep-MI/neuroreg/issues
33
+ Keywords: python,Registration,3D Image,MRI,PyTorch
34
+ Classifier: Operating System :: OS Independent
35
+ Classifier: Environment :: Console
36
+ Classifier: Programming Language :: Python :: 3 :: Only
37
+ Classifier: Programming Language :: Python :: 3.10
38
+ Classifier: Programming Language :: Python :: 3.11
39
+ Classifier: Programming Language :: Python :: 3.12
40
+ Classifier: Programming Language :: Python :: 3.13
41
+ Classifier: Natural Language :: English
42
+ Classifier: License :: OSI Approved :: MIT License
43
+ Classifier: Intended Audience :: Science/Research
44
+ Requires-Python: >=3.10
45
+ Description-Content-Type: text/markdown
46
+ License-File: LICENSE
47
+ Requires-Dist: nibabel>=5.1
48
+ Requires-Dist: numpy>=1.25
49
+ Requires-Dist: psutil
50
+ Requires-Dist: scikit-image>=0.21
51
+ Requires-Dist: scipy>=1.11
52
+ Requires-Dist: torch>=2.0.1
53
+ Provides-Extra: build
54
+ Requires-Dist: build; extra == "build"
55
+ Requires-Dist: twine; extra == "build"
56
+ Provides-Extra: doc
57
+ Requires-Dist: furo!=2023.8.17; extra == "doc"
58
+ Requires-Dist: matplotlib>=3.5; extra == "doc"
59
+ Requires-Dist: memory-profiler; extra == "doc"
60
+ Requires-Dist: myst-parser; extra == "doc"
61
+ Requires-Dist: numpydoc; extra == "doc"
62
+ Requires-Dist: sphinx<8,>=7.3; extra == "doc"
63
+ Requires-Dist: sphinxcontrib-bibtex; extra == "doc"
64
+ Requires-Dist: sphinx-copybutton; extra == "doc"
65
+ Requires-Dist: sphinx-design; extra == "doc"
66
+ Requires-Dist: sphinx-gallery; extra == "doc"
67
+ Requires-Dist: sphinx-issues; extra == "doc"
68
+ Requires-Dist: pypandoc; extra == "doc"
69
+ Requires-Dist: nbsphinx; extra == "doc"
70
+ Requires-Dist: IPython; extra == "doc"
71
+ Requires-Dist: ipykernel; extra == "doc"
72
+ Provides-Extra: style
73
+ Requires-Dist: bibclean; extra == "style"
74
+ Requires-Dist: codespell; extra == "style"
75
+ Requires-Dist: pydocstyle[toml]; extra == "style"
76
+ Requires-Dist: ruff; extra == "style"
77
+ Provides-Extra: test
78
+ Requires-Dist: pytest>=8.2.2; extra == "test"
79
+ Requires-Dist: pytest-cov; extra == "test"
80
+ Requires-Dist: pytest-timeout; extra == "test"
81
+ Provides-Extra: all
82
+ Requires-Dist: neuroreg[build]; extra == "all"
83
+ Requires-Dist: neuroreg[doc]; extra == "all"
84
+ Requires-Dist: neuroreg[style]; extra == "all"
85
+ Requires-Dist: neuroreg[test]; extra == "all"
86
+ Provides-Extra: full
87
+ Requires-Dist: neuroreg[all]; extra == "full"
88
+ Dynamic: license-file
89
+
90
+ [![PyPI version](https://badge.fury.io/py/neuroreg.svg)](https://pypi.org/project/neuroreg/)
91
+
92
+ # NeuroReg
93
+
94
+ NeuroReg is a package for the robust registration of 3D neuroimaging data (e.g. MRI).
95
+ It supports both image-to-image (within and cross modal) as well as image to
96
+ landmark (WM-surface) or segmentation. It uses PyTorch's automatic differentiation
97
+ for gradient-based optimisations and can run efficiently on a GPU.
98
+
99
+ The main user-facing tools are:
100
+
101
+ - **`robreg`** – Highly accurate and robust same modality image-to-image registration
102
+ (IRLS based, analogous to FreeSurfer's `mri_robust_register`)
103
+ - **`coreg`** – Image-to-image cross-modal registration
104
+ (gradient-descent with normalized mutual information NMI, cf. `mri_coreg`)
105
+ - **`bbreg`** – boundary-based registration using cortical WM surfaces or segmentations
106
+ (analogous to FreeSurfer's `bbregister` / `mri_segreg`)
107
+ - **`lta`** – transform comparison / inversion / concatenation utilities
108
+
109
+ This project is a work-in-progress in an early development stage. It is developed by
110
+ the creator of FreeSurfer's `mri_robust_register` as an efficient pure Python
111
+ replacement (with GPU support) and cross-modal extensions to support all your medical
112
+ imaging reistration needs, with a focus on high accuracy and speed. If you find it
113
+ useful for a publication, please cite the relevant papers (see [References](#References)).
114
+
115
+ ## Installation
116
+
117
+ ```bash
118
+ pip install neuroreg
119
+ ```
120
+
121
+ ## Command-line interface
122
+
123
+ ### `robreg` — image-to-image registration
124
+
125
+ Registers a moving image to a reference image using a multi-resolution
126
+ IRLS-based robust registration path with Tukey weighting.
127
+
128
+ This path is currently intended for **same-contrast or very similar-contrast**
129
+ image pairs.
130
+ On Apple MPS, the current public IRLS path falls back to CPU with a warning due
131
+ to lack of double precision support on MPS.
132
+
133
+ ```
134
+ robreg --mov <moving.nii.gz> --ref <reference.nii.gz> --out <output.lta> [options]
135
+ ```
136
+
137
+ Run `robreg -h` for a full argument summary with defaults.
138
+
139
+ **Required arguments**
140
+
141
+ | Argument | Description |
142
+ |--------------|---------------------------------------------------|
143
+ | `--mov FILE` | Moving (source) image (NIfTI or MGZ). |
144
+ | `--ref FILE` | Reference (target/fixed) image (NIfTI or MGZ). |
145
+ | `--out LTA` | Output LTA file for the recovered transformation. |
146
+
147
+ **Options**
148
+
149
+ | Argument | Default | Description |
150
+ |-------------------|---------|--------------------------------------------------------------------------------------------------------------------|
151
+ | `--dof {6}` | `6` | Degrees of freedom. The public `robreg` path is currently rigid-only. |
152
+ | `--nmax N` | `5` | Maximum number of outer IRLS iterations per pyramid level. |
153
+ | `--sat FLOAT` | `6.0` | Tukey biweight saturation threshold. |
154
+ | `--nosym` | off | Disable symmetric halfway-space registration and run directed registration. Symmetric registration is the default. |
155
+ | `--noinit` | off | Skip centroid-based initialization and start from identity (like FreeSurfer `--noinit`). |
156
+ | `--mapped FILE` | — | Save the warped moving image. |
157
+ | `--outliers FILE` | — | Save an outlier map (`1 - Tukey weights`). |
158
+ | `--verbose` | off | Enable INFO-level logging. |
159
+ | `--debug` | off | Enable DEBUG-level logging. |
160
+
161
+ **Example**
162
+
163
+ ```bash
164
+ robreg --mov T1_repeat.nii.gz --ref T1_baseline.mgz --out T1_repeat_to_T1_baseline.lta --verbose
165
+ ```
166
+
167
+ ---
168
+
169
+ ### `coreg` — image-based cross-modal registration
170
+
171
+ This is the image-based gradient-descent registration path used for
172
+ **cross-sequence / cross-modal** registration when no surfaces or segmentation
173
+ are available. In practice it is the package's image-only counterpart to
174
+ FreeSurfer's `mri_coreg`.
175
+
176
+ ```
177
+ coreg --mov <moving.nii.gz> --ref <reference.nii.gz> --out <output.lta> [options]
178
+ ```
179
+
180
+ **Options**
181
+
182
+ | Argument | Default | Description |
183
+ |--------------------|---------|-----------------------------------------------------------------------|
184
+ | `--dof {3,6,9,12}` | `6` | Degrees of freedom: 3=translation, 6=rigid, 9=rigid+scale, 12=affine. |
185
+ | `--n_iters N` | auto | Maximum optimisation iterations per pyramid level. |
186
+ | `--noinit` | off | Skip centroid-based initialization and start from identity. |
187
+ | `--device DEVICE` | `cpu` | PyTorch device, e.g. `cpu` or `cuda`. |
188
+ | `--verbose` | off | Enable INFO-level logging. |
189
+ | `--debug` | off | Enable DEBUG-level logging. |
190
+
191
+ **Example**
192
+
193
+ ```bash
194
+ coreg --mov T2.nii.gz --ref T1.mgz --out T2_to_T1.lta --dof 6 --verbose
195
+ ```
196
+
197
+ ---
198
+
199
+ ### `bbreg` — boundary-based registration
200
+
201
+ Registers a moving image to a T1 anatomy using cortical surface meshes
202
+ (white matter / grey matter boundary). The tissue contrast direction
203
+ (T1-like: WM > GM, or T2-like: GM > WM) is auto-detected from the image
204
+ when not specified.
205
+
206
+ Surface input can be provided in three ways:
207
+
208
+ **Mode A — FreeSurfer / FastSurfer subject directory** (recommended)
209
+
210
+ ```
211
+ bbreg --mov <moving.nii.gz> --subject_dir <subject_dir> --out <output.lta> [options]
212
+ ```
213
+
214
+ The subject directory must contain `surf/lh.white`, `surf/rh.white`, and
215
+ `mri/orig.mgz` (standard FreeSurfer / FastSurfer output layout).
216
+
217
+ **Mode B — explicit surface files**
218
+
219
+ ```
220
+ bbreg --mov <moving.nii.gz> --lh_surf <lh.white> --rh_surf <rh.white> \
221
+ --ref <T1.mgz> --out <output.lta> [options]
222
+ ```
223
+
224
+ **Mode C — segmentation file (no pre-built surfaces needed)**
225
+
226
+ ```
227
+ bbreg --mov <moving.nii.gz> --seg <aparc+aseg.mgz> --out <output.lta> [options]
228
+ ```
229
+
230
+ The WM/GM boundary surface is extracted on-the-fly from a parcellation or
231
+ aseg file (e.g. `aparc+aseg.mgz`, `aseg.mgz`, or NIfTI) via marching cubes.
232
+ The segmentation header provides the reference geometry; `--ref` must *not* be
233
+ specified in this mode.
234
+
235
+ **Required arguments**
236
+
237
+ | Argument | Description |
238
+ |------------------------------|------------------------------------------------------------------------|
239
+ | `--mov FILE` | Moving image to register (NIfTI or MGZ). |
240
+ | `--out LTA` | Output LTA file for the recovered transformation. |
241
+ | `--subject_dir DIR` | *(Mode A)* Subject directory with surfaces and `mri/orig.mgz`. |
242
+ | `--lh_surf / --rh_surf FILE` | *(Mode B)* Explicit left / right white surface files. |
243
+ | `--ref FILE` | *(Mode B)* Reference T1 image (required with explicit surfaces). |
244
+ | `--seg FILE` | *(Mode C)* Parcellation / aseg file; surfaces extracted automatically. |
245
+
246
+ **Options**
247
+
248
+ | Argument | Default | Description |
249
+ |----------------------------------------|------------|--------------------------------------------------------------------------------------------------------|
250
+ | `--dof {6,9,12}` | `6` | Degrees of freedom: 6=rigid, 9=rigid+scale, 12=affine. |
251
+ | `--contrast {t1,t2}` | auto | Tissue contrast: `t1` (WM>GM) or `t2` (GM>WM). Auto-detected if omitted. |
252
+ | `--cost {contrast,gradient,both}` | `contrast` | BBR cost term. |
253
+ | `--wm_proj_abs MM` | `1.4` | WM projection depth in mm. |
254
+ | `--gm_proj_frac FRAC` | `0.5` | GM projection as fraction of cortical thickness. |
255
+ | `--slope SLOPE` | `0.5` | Slope of the BBR sigmoid cost function. |
256
+ | `--gradient_weight W` | `0.0` | Weight for gradient cost term when `--cost=both`. |
257
+ | `--n_iters N` | `500` | Number of RMSprop optimisation iterations. |
258
+ | `--lr LR` | `0.005` | Optimiser learning rate. |
259
+ | `--subsample N` | `2` | Use every N-th surface vertex (1 = all). |
260
+ | `--lh_thickness / --rh_thickness FILE` | — | *(Mode B)* Cortical thickness files for GM projection. |
261
+ | `--seg_smooth_sigma SIGMA` | `0.5` | *(Mode C)* Gaussian pre-blur sigma (voxels) before marching cubes. |
262
+ | `--seg_mc_level LEVEL` | `0.45` | *(Mode C)* Marching-cubes iso-level. |
263
+ | `--seg_smooth_iters N` | `50` | *(Mode C)* Taubin smoothing iterations after marching cubes. |
264
+ | `--init_lta FILE` | — | Initialise from an existing LTA transform (e.g. from a prior `robreg` run or a previous `bbreg` pass). |
265
+ | `--device DEVICE` | `cpu` | PyTorch device, e.g. `cpu` or `cuda`. |
266
+ | `--verbose` | off | Enable INFO-level logging. |
267
+ | `--debug` | off | Enable DEBUG-level logging. |
268
+
269
+ **Examples**
270
+
271
+ ```bash
272
+ # Mode A: register fMRI to T1 using a FastSurfer subject directory
273
+ bbreg --mov fMRI.nii.gz --subject_dir /data/subjects/sub-01 --out fMRI_to_T1.lta
274
+
275
+ # Mode B: register T2 to T1 with explicit surfaces and thickness files
276
+ bbreg --mov T2.nii.gz \
277
+ --lh_surf /data/subjects/sub-01/surf/lh.white \
278
+ --rh_surf /data/subjects/sub-01/surf/rh.white \
279
+ --lh_thickness /data/subjects/sub-01/surf/lh.thickness \
280
+ --rh_thickness /data/subjects/sub-01/surf/rh.thickness \
281
+ --ref /data/subjects/sub-01/mri/orig.mgz \
282
+ --out T2_to_T1.lta --contrast t2
283
+
284
+ # Mode C: register fMRI using a segmentation (no surface files required)
285
+ bbreg --mov fMRI.nii.gz --seg /data/subjects/sub-01/mri/aparc+aseg.mgz \
286
+ --out fMRI_to_T1.lta
287
+ ```
288
+
289
+ Run `bbreg -h` for a full argument summary with defaults.
290
+
291
+ ---
292
+
293
+ ### `lta` — LTA transform utilities
294
+
295
+ Unified command for manipulating FreeSurfer LTA transform files with three
296
+ subcommands: `diff`, `invert`, and `concat`.
297
+
298
+ ```
299
+ lta diff LTA1 [LTA2] [options] # Compare transforms
300
+ lta invert INPUT OUTPUT # Invert a transform
301
+ lta concat LTA1 LTA2 OUTPUT # Concatenate two transforms
302
+ ```
303
+
304
+ ---
305
+
306
+ #### `lta diff` — Compare transforms
307
+
308
+ Computes distance metrics between two LTA transforms, or between a single
309
+ transform and identity. Replicates the functionality of FreeSurfer's `lta_diff`.
310
+
311
+ **Usage**
312
+
313
+ ```
314
+ lta diff LTA1 [LTA2] [--dist {1,2,3,4,5,7}] [--radius MM] [--normdiv FLOAT]
315
+ [--invert1] [--invert2]
316
+ ```
317
+
318
+ **Distance types**
319
+
320
+ | `--dist` | Metric |
321
+ |----------|------------------------------------------------------------------------|
322
+ | `1` | Rigid transform distance: √(‖log R_d‖² + ‖T_d‖²) |
323
+ | `2` | Affine RMS distance (Jenkinson 1999) — **default** |
324
+ | `3` | Mean displacement at the 8 corners of the source volume (mm) |
325
+ | `4` | Max displacement on a sphere of radius `r` |
326
+ | `5` | Determinant of M1 (or M1·M2 when two transforms are given) |
327
+ | `7` | Polar decomposition: rotation, shear, scales, translation, determinant |
328
+
329
+ **Options**
330
+
331
+ | Argument | Default | Description |
332
+ |------------------------|---------|--------------------------------------------------------|
333
+ | `--dist {1,2,3,4,5,7}` | `2` | Distance type (see table above). |
334
+ | `--radius MM` | `100` | Sphere / RMS radius in mm (used by dist 2 and 4). |
335
+ | `--normdiv FLOAT` | `1` | Divide the final distance by this value (must be > 0). |
336
+ | `--invert1` | off | Invert LTA1 before comparison. |
337
+ | `--invert2` | off | Invert LTA2 before comparison (requires a second LTA). |
338
+
339
+ **Examples**
340
+
341
+ ```bash
342
+ # Affine RMS distance between two registrations (default metric)
343
+ lta diff myreg.lta ref.lta
344
+
345
+ # Rigid distance
346
+ lta diff myreg.lta ref.lta --dist 1
347
+
348
+ # Polar decomposition of a single transform
349
+ lta diff myreg.lta --dist 7
350
+ ```
351
+
352
+ ---
353
+
354
+ #### `lta invert` — Invert a transform
355
+
356
+ Inverts an LTA transform and writes the result to a new file. The output is
357
+ always stored as LINEAR_RAS_TO_RAS with src and dst geometry swapped.
358
+
359
+ **Usage**
360
+
361
+ ```
362
+ lta invert INPUT OUTPUT
363
+ ```
364
+
365
+ **Examples**
366
+
367
+ ```bash
368
+ # Invert a registration
369
+ lta invert T1_to_MNI.lta MNI_to_T1.lta
370
+
371
+ # Invert twice to verify round-trip
372
+ lta invert fwd.lta inv.lta
373
+ lta invert inv.lta fwd_again.lta
374
+ ```
375
+
376
+ ---
377
+
378
+ #### `lta concat` — Concatenate transforms
379
+
380
+ Concatenates two LTA transforms. If `LTA1` maps A→B and `LTA2` maps B→C, the
381
+ output maps A→C. Equivalent to FreeSurfer's `mri_concatenate_lta`.
382
+
383
+ **Usage**
384
+
385
+ ```
386
+ lta concat LTA1 LTA2 OUTPUT
387
+ ```
388
+
389
+ **Examples**
390
+
391
+ ```bash
392
+ # Concatenate fMRI→T1 and T1→MNI to get fMRI→MNI
393
+ lta concat fMRI_to_T1.lta T1_to_MNI.lta fMRI_to_MNI.lta
394
+
395
+ # Chain multiple registrations
396
+ lta concat moving_to_intermediate.lta intermediate_to_fixed.lta moving_to_fixed.lta
397
+ ```
398
+
399
+ **Notes**
400
+
401
+ - All metrics are numerically matched to FreeSurfer's `lta_diff` (except for a
402
+ known bug in the C++ single-transform corner metric, which is fixed here).
403
+ - When only one LTA is supplied to `diff`, the transform is compared against identity.
404
+ - Run `lta --help` or `lta <subcommand> --help` for detailed usage.
405
+
406
+ ## Python API
407
+
408
+ ```python
409
+ import nibabel as nib
410
+
411
+ from neuroreg import bbreg, coreg, robreg
412
+
413
+ # Public robust image-to-image registration (IRLS-backed).
414
+ # Intended for same-/similar-contrast pairs; symmetric mode is the default.
415
+ # On Apple MPS, this path currently warns and falls back to CPU.
416
+ transform_robreg = robreg("T1_repeat.nii.gz", "T1_baseline.mgz")
417
+
418
+ # The same public robreg path with pre-loaded nibabel images.
419
+ mov_img = nib.load("T1_repeat.nii.gz")
420
+ ref_img = nib.load("T1_baseline.mgz")
421
+ transform_robreg_loaded = robreg(mov_img, ref_img)
422
+
423
+ # Image-based cross-modal registration path for cases where no
424
+ # white-matter surface or segmentation is available.
425
+ transform_coreg = coreg("T2.nii.gz", "T1.mgz", loss_name="nmi")
426
+
427
+ # Surface-based (BBR) registration — Mode A: subject directory
428
+ transform_bbreg = bbreg(
429
+ mov="fMRI.nii.gz",
430
+ subject_dir="/data/subjects/sub-01",
431
+ lta_name="fMRI_to_T1.lta",
432
+ dof=6,
433
+ )
434
+
435
+ # Surface-based (BBR) registration — Mode B: explicit surface files
436
+ transform_bbreg = bbreg(
437
+ mov="T2.nii.gz",
438
+ lh_surf="/data/subjects/sub-01/surf/lh.white",
439
+ rh_surf="/data/subjects/sub-01/surf/rh.white",
440
+ lh_thickness="/data/subjects/sub-01/surf/lh.thickness",
441
+ rh_thickness="/data/subjects/sub-01/surf/rh.thickness",
442
+ ref="/data/subjects/sub-01/mri/orig.mgz",
443
+ lta_name="T2_to_T1.lta",
444
+ contrast="t2",
445
+ )
446
+
447
+ # Surface-based (BBR) registration — Mode C: segmentation (no surface files needed)
448
+ transform_bbreg = bbreg(
449
+ mov="fMRI.nii.gz",
450
+ seg="/data/subjects/sub-01/mri/aparc+aseg.mgz",
451
+ lta_name="fMRI_to_T1.lta",
452
+ )
453
+
454
+ # For debugging or inspection, request the fitted model explicitly.
455
+ transform_bbreg, model_bbreg = bbreg(
456
+ mov="fMRI.nii.gz",
457
+ subject_dir="/data/subjects/sub-01",
458
+ return_model=True,
459
+ )
460
+ ```
461
+
462
+ ## Degrees of freedom
463
+
464
+ Current DOF support is:
465
+
466
+ | Command / API path | Supported DOF |
467
+ |------------------------------|---------------------|
468
+ | `robreg` / public `robreg()` | `6` only |
469
+ | `coreg` / public `coreg()` | `3`, `6`, `9`, `12` |
470
+ | `bbreg` / public `bbreg()` | `6`, `9`, `12` |
471
+
472
+ The public `robreg` path is intentionally rigid-only for now because it tracks
473
+ the current IRLS implementation.
474
+
475
+ Also note that the current public `robreg` path is aimed at same-/similar-contrast
476
+ registration. For cross-sequence alignment such as T2→T1, the current options are
477
+ `coreg` (image-based GD) or `bbreg` when a segmentation or surfaces are
478
+ available.
479
+
480
+ ## API Documentation
481
+
482
+ The API Documentation can be found at https://deep-mi.org/neuroreg .
483
+
484
+ ## References
485
+
486
+ If you use this software for a publication please cite:
487
+
488
+ - Reuter, Rosas, Fischl (2010).
489
+ Highly accurate inverse consistent registration: a robust approach.
490
+ NeuroImage 53(4):1181-1196.
491
+ https://doi.org/10.1016/j.neuroimage.2010.07.040
492
+
493
+ - Reuter, Schmansky, Rosas, Fischl (2012).
494
+ Within-subject template estimation for unbiased longitudinal image analysis.
495
+ NeuroImage 61(4):1402-1418.
496
+ https://doi.org/10.1016/j.neuroimage.2012.02.084
497
+
498
+ - Reuter, Fischl (2011).
499
+ Avoiding asymmetry-induced bias in longitudinal image processing.
500
+ NeuroImage 57(1):19-21.
501
+ https://doi.org/10.1016/j.neuroimage.2011.02.076
502
+
503
+ If you use `bbreg` specifically, please also cite:
504
+
505
+ - Greve, Fischl (2009).
506
+ Accurate and robust brain image alignment using boundary-based registration.
507
+ NeuroImage 48(1):63-72.
508
+ https://doi.org/10.1016/j.neuroimage.2009.06.060
509
+
510
+ We invite you to check out our lab webpage at https://deep-mi.org