@@ -215,22 +215,27 @@ def to_filename(self, filename, fmt='X5', moving=None):
215
215
return super (Affine , self ).to_filename (filename , fmt = fmt )
216
216
217
217
218
- def load (filename , reference = None ):
218
+ def load (filename , fmt = 'X5' , reference = None ):
219
219
''' Load a linear transform '''
220
- with open (filename ) as itkfile :
221
- itkxfm = itkfile .read ().splitlines ()
222
220
223
- parameters = np .fromstring (itkxfm [3 ].split (':' )[- 1 ].strip (), dtype = float , sep = ' ' )
224
- offset = np .fromstring (itkxfm [4 ].split (':' )[- 1 ].strip (), dtype = float , sep = ' ' )
225
- if len (parameters ) == 12 :
226
- matrix = from_matvec (parameters [:9 ].reshape ((3 , 3 )), parameters [9 :])
227
- c_neg = from_matvec (np .eye (3 ), offset * - 1.0 )
228
- c_pos = from_matvec (np .eye (3 ), offset )
229
- matrix = LPS .dot (c_pos .dot (matrix .dot (c_neg .dot (LPS ))))
221
+ if fmt .lower () in ['itk' , 'ants' , 'elastix' , 'nifty' ]:
222
+ with open (filename ) as itkfile :
223
+ itkxfm = itkfile .read ().splitlines ()
224
+
225
+ parameters = np .fromstring (itkxfm [3 ].split (':' )[- 1 ].strip (), dtype = float , sep = ' ' )
226
+ offset = np .fromstring (itkxfm [4 ].split (':' )[- 1 ].strip (), dtype = float , sep = ' ' )
227
+ if len (parameters ) == 12 :
228
+ matrix = from_matvec (parameters [:9 ].reshape ((3 , 3 )), parameters [9 :])
229
+ c_neg = from_matvec (np .eye (3 ), offset * - 1.0 )
230
+ c_pos = from_matvec (np .eye (3 ), offset )
231
+ matrix = LPS .dot (c_pos .dot (matrix .dot (c_neg .dot (LPS ))))
232
+
233
+ # if fmt.lower() == 'afni':
234
+ # parameters = LPS.dot(self.matrix.dot(LPS))
235
+ # parameters = parameters[:3, :].reshape(-1).tolist()
230
236
231
237
if reference and isinstance (reference , str ):
232
238
reference = loadimg (reference )
233
-
234
239
return Affine (matrix , reference )
235
240
236
241
0 commit comments