@@ -14,18 +14,17 @@ def split_and_deoblique_func(in_file):
14
14
import numpy as np
15
15
out_files = []
16
16
for i , img in enumerate (iter_img (in_file )):
17
- out_file = os .path .abspath ('vol%04d.nii.gz' % i )
17
+ out_file = os .path .abspath ('vol%04d.nii.gz' % i )
18
18
affine = img .affine
19
- affine [:3 ,:3 ] = np .diag (np .diag (affine [:3 , :3 ]))
19
+ affine [:3 , :3 ] = np .diag (np .diag (affine [:3 , :3 ]))
20
20
nb .Nifti1Image (np .asanyarray (img .dataobj ), affine , img .header ).to_filename (out_file )
21
21
out_files .append (out_file )
22
22
return out_files
23
23
24
24
25
25
def afni2itk_func (in_file ):
26
26
import os
27
- from scipy .io import loadmat , savemat
28
- from numpy import loadtxt , around , hstack , vstack , zeros , float64
27
+ from numpy import loadtxt , hstack , vstack , zeros , float64
29
28
30
29
def read_afni_affine (input_file , debug = False ):
31
30
orig_afni_mat = loadtxt (input_file )
@@ -34,13 +33,13 @@ def read_afni_affine(input_file, debug=False):
34
33
35
34
output = []
36
35
for i in range (orig_afni_mat .shape [0 ]):
37
- output .append (vstack ((orig_afni_mat [i ,:].reshape (3 , 4 , order = 'C' ), [0 , 0 , 0 , 1 ])))
36
+ output .append (vstack ((orig_afni_mat [i , :].reshape (3 , 4 , order = 'C' ), [0 , 0 , 0 , 1 ])))
38
37
return output
39
38
40
39
def get_ants_dict (affine , debug = False ):
41
40
out_dict = {}
42
- out_dict [ 'AffineTransform_double_3_3' ] = hstack (
43
- ( affine [: 3 , : 3 ]. reshape ( 1 , - 1 ), affine [: 3 , 3 ]. reshape ( 1 , - 1 ))) .reshape (- 1 , 1 ).astype (float64 )
41
+ ants_affine_2d = hstack (( affine [: 3 , : 3 ]. reshape ( 1 , - 1 ), affine [: 3 , 3 ]. reshape ( 1 , - 1 )))
42
+ out_dict [ 'AffineTransform_double_3_3' ] = ants_affine_2d .reshape (- 1 , 1 ).astype (float64 )
44
43
out_dict ['fixed' ] = zeros ((3 , 1 ))
45
44
if debug :
46
45
print (out_dict )
@@ -51,11 +50,18 @@ def get_ants_dict(affine, debug=False):
51
50
with open (out_file , 'w' ) as fp :
52
51
fp .write ("#Insight Transform File V1.0\n " )
53
52
for i , affine in enumerate (read_afni_affine (in_file )):
54
- fp .write ("#Transform %d\n " % i )
53
+ fp .write ("#Transform %d\n " % i )
55
54
fp .write ("Transform: AffineTransform_double_3_3\n " )
56
55
trans_dict = get_ants_dict (affine )
57
- fp .write ("Parameters: " + ' ' .join (["%g" % i for i in list (trans_dict ['AffineTransform_double_3_3' ])]) + "\n " )
58
- fp .write ("FixedParameters: " + ' ' .join (["%g" % i for i in list (trans_dict ['fixed' ])]) + "\n " )
56
+
57
+ params_list = ["%g" % i for i in list (trans_dict ['AffineTransform_double_3_3' ])]
58
+ params_str = ' ' .join (params_list )
59
+ fp .write ("Parameters: " + params_str + "\n " )
60
+
61
+ fixed_params_list = ["%g" % i for i in list (trans_dict ['fixed' ])]
62
+ fixed_params_str = ' ' .join (fixed_params_list )
63
+ fp .write ("FixedParameters: " + ' ' .join (fixed_params_str ) + "\n " )
64
+
59
65
return out_file
60
66
61
67
0 commit comments