2
2
import numpy as np
3
3
from scipy .io import savemat as _save_mat
4
4
from nibabel .affines import from_matvec
5
- from .base import StringBasedStruct , _read_mat
5
+ from .base import StringBasedStruct , _read_mat , TransformFileError
6
6
7
7
LPS = np .diag ([- 1 , - 1 , 1 , 1 ])
8
8
@@ -23,7 +23,7 @@ class ITKLinearTransform(StringBasedStruct):
23
23
def __init__ (self , parameters = None , offset = None ):
24
24
"""Initialize with default offset and index."""
25
25
super ().__init__ ()
26
- self .structarr ['index' ] = 1
26
+ self .structarr ['index' ] = 0
27
27
self .structarr ['offset' ] = offset or [0 , 0 , 0 ]
28
28
self .structarr ['parameters' ] = np .eye (4 )
29
29
if parameters is not None :
@@ -76,7 +76,7 @@ def to_string(self, banner=None):
76
76
string = '%s'
77
77
78
78
if banner is None :
79
- banner = self .structarr ['index' ] == 1
79
+ banner = self .structarr ['index' ] == 0
80
80
81
81
if banner :
82
82
string = '#Insight Transform File V1.0\n %s'
@@ -103,7 +103,7 @@ def from_matlab_dict(cls, mdict, index=None):
103
103
if index is not None :
104
104
raise NotImplementedError
105
105
106
- sa ['index' ] = 1
106
+ sa ['index' ] = 0
107
107
parameters = np .eye (4 , dtype = 'f4' )
108
108
parameters [:3 , :3 ] = mdict ['AffineTransform_float_3_3' ][:- 3 ].reshape ((3 , 3 ))
109
109
parameters [:3 , 3 ] = mdict ['AffineTransform_float_3_3' ][- 3 :].flatten ()
@@ -116,7 +116,7 @@ def from_ras(cls, ras, index=0):
116
116
"""Create an ITK affine from a nitransform's RAS+ matrix."""
117
117
tf = cls ()
118
118
sa = tf .structarr
119
- sa ['index' ] = index + 1
119
+ sa ['index' ] = index
120
120
sa ['parameters' ] = LPS .dot (ras .dot (LPS ))
121
121
return tf
122
122
@@ -171,7 +171,7 @@ def xforms(self, value):
171
171
172
172
# Update indexes
173
173
for i , val in enumerate (self ._xforms ):
174
- val ['index' ] = i + 1
174
+ val ['index' ] = i
175
175
176
176
def __getitem__ (self , idx ):
177
177
"""Allow dictionary access to the transforms."""
@@ -197,7 +197,7 @@ def to_string(self):
197
197
"""Convert to a string directly writeable to file."""
198
198
strings = []
199
199
for i , xfm in enumerate (self .xforms ):
200
- xfm .structarr ['index' ] = i + 1
200
+ xfm .structarr ['index' ] = i
201
201
strings .append (xfm .to_string ())
202
202
return '\n ' .join (strings )
203
203
0 commit comments