Skip to content

Commit

Permalink
ENH: Add ITK-LTA conversion test
Browse files Browse the repository at this point in the history
Also, finally fixes #64.
  • Loading branch information
oesteban committed Mar 19, 2020
1 parent 4acfdbc commit 970da02
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
2 changes: 1 addition & 1 deletion nitransforms/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, matrix=None, reference=None):
raise TypeError('Matrix is not square.')
self._matrix = matrix

if np.any(self._matrix[3, :] != (0, 0, 0, 1)):
if not np.allclose(self._matrix[3, :], (0, 0, 0, 1)):
raise ValueError("Matrix does not represent a valid transform.")

def __eq__(self, other):
Expand Down
30 changes: 14 additions & 16 deletions nitransforms/tests/data/regressions/robust_register.lta
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
# transform file /home/oesteban/tmp/fmriprep-ds005/fprep-work/fmriprep_wf/single_subject_01_wf/anat_preproc_wf/surface_recon_wf/fsnative2t1w_xfm/T1_robustreg.lta
# created by oesteban on Sat Mar 14 19:28:37 2020

type = 1 # LINEAR_RAS_TO_RAS
nxforms = 1
mean = 129.0000 157.0000 132.0000
sigma = 10000.0000
1 4 4
9.999999403953552e-01 -1.698292035143822e-04 1.542967074783519e-04 -1.678466796875000e-04
1.698438863968477e-04 9.999999403953552e-01 -9.513227996649221e-05 -1.318359375000000e-02
-1.542805403005332e-04 9.515848068986088e-05 9.999999403953552e-01 -6.271362304687500e-03
0.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00 9.999999403953552e-01
1.000000000000000e+00 1.698439009487629e-04 -1.542805694043636e-04 1.691182987997308e-04
-1.698292180662975e-04 1.000000000000000e+00 9.515849524177611e-05 1.318416278809309e-02
1.542967220302671e-04 -9.513228724244982e-05 1.000000000000000e+00 6.270134821534157e-03
0.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00 1.000000000000000e+00
src volume info
valid = 1 # volume info valid
filename = /oak/stanford/groups/russpold/data/openfmri/derivatives/ds000005/freesurfer-6.0.1/sub-01/mri/T1.mgz
volume = 256 256 256
voxelsize = 1.000000000000000e+00 1.000000000000000e+00 1.000000000000000e+00
xras = -9.999999403953552e-01 0.000000000000000e+00 0.000000000000000e+00
yras = 0.000000000000000e+00 0.000000000000000e+00 -9.999999403953552e-01
zras = 0.000000000000000e+00 9.999999403953552e-01 0.000000000000000e+00
cras = -9.999847412109375e-01 -5.000015258789062e+00 -1.000038146972656e+00
dst volume info
valid = 1 # volume info valid
filename = /oak/stanford/groups/russpold/data/openfmri/ds000005/sub-01/anat/sub-01_T1w.nii.gz
volume = 160 192 192
voxelsize = 1.000000000000000e+00 1.333333015441895e+00 1.333333015441895e+00
xras = 1.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00
yras = 0.000000000000000e+00 1.000000000000000e+00 0.000000000000000e+00
zras = 0.000000000000000e+00 0.000000000000000e+00 1.000000000000000e+00
cras = -1.000000000000000e+00 -5.000030517578125e+00 -1.000030517578125e+00
dst volume info
valid = 1 # volume info valid
filename = /oak/stanford/groups/russpold/data/openfmri/derivatives/ds000005/freesurfer-6.0.1/sub-01/mri/T1.mgz
volume = 256 256 256
voxelsize = 1.000000000000000e+00 1.000000000000000e+00 1.000000000000000e+00
xras = -9.999999403953552e-01 0.000000000000000e+00 0.000000000000000e+00
yras = 0.000000000000000e+00 0.000000000000000e+00 -9.999999403953552e-01
zras = 0.000000000000000e+00 9.999999403953552e-01 0.000000000000000e+00
cras = -9.999847412109375e-01 -5.000015258789062e+00 -1.000038146972656e+00
fscale 0.100000
5 changes: 5 additions & 0 deletions nitransforms/tests/data/regressions/robust_register.tfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Insight Transform File V1.0
#Transform 0
Transform: AffineTransform_double_3_3
Parameters: 1 -0.00016982921806629747 -0.00015429673658218235 0.00016984390094876289 1 9.5132294518407434e-05 0.00015428056940436363 -9.5158495241776109e-05 1 0.00016784669423941523 0.013183594681322575 -0.0062713632360100746
FixedParameters: 0 0 0
12 changes: 12 additions & 0 deletions nitransforms/tests/test_conversions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""Conversions between formats."""
import numpy as np
import pytest
from .. import linear as _l

def test_conversions(data_path):
lta = _l.load(data_path / "regressions" / "robust_register.lta", fmt="lta")
itk = _l.load(data_path / "regressions" / "robust_register.tfm", fmt="itk")

assert np.allclose(lta.matrix, itk.matrix)

0 comments on commit 970da02

Please sign in to comment.