@@ -43,41 +43,34 @@ def load_ants_h5(filename: Path) -> nt.TransformChain:
43
43
return nt .TransformChain ([warp_transform , nt .Affine (affine )])
44
44
45
45
46
+ FIXED_PARAMS = np .array ([
47
+ 193.0 , 229.0 , 193.0 ,
48
+ 96.0 , 132.0 , - 78.0 ,
49
+ 1.0 , 1.0 , 1.0 ,
50
+ - 1.0 , 0.0 , 0.0 ,
51
+ 0.0 , - 1.0 , 0.0 ,
52
+ 0.0 , 0.0 , 1.0 ,
53
+ ]) # fmt:skip
54
+
55
+
46
56
def parse_combined_hdf5 (h5_fn , to_ras = True ):
47
57
# Borrowed from https://github.com/feilong/process
48
58
# process.resample.parse_combined_hdf5()
49
59
h = h5py .File (h5_fn )
50
60
xform = ITKCompositeH5 .from_h5obj (h )
51
61
affine = xform [0 ].to_ras ()
62
+ transform2 = h ['TransformGroup' ]['2' ]
52
63
# Confirm these transformations are applicable
53
- assert (
54
- h ['TransformGroup' ]['2' ]['TransformType' ][:][0 ] == b'DisplacementFieldTransform_float_3_3'
55
- )
56
- assert np .array_equal (
57
- h ['TransformGroup' ]['2' ]['TransformFixedParameters' ][:],
58
- np .array (
59
- [
60
- 193.0 ,
61
- 229.0 ,
62
- 193.0 ,
63
- 96.0 ,
64
- 132.0 ,
65
- - 78.0 ,
66
- 1.0 ,
67
- 1.0 ,
68
- 1.0 ,
69
- - 1.0 ,
70
- 0.0 ,
71
- 0.0 ,
72
- 0.0 ,
73
- - 1.0 ,
74
- 0.0 ,
75
- 0.0 ,
76
- 0.0 ,
77
- 1.0 ,
78
- ]
79
- ),
80
- )
64
+ if transform2 ['TransformType' ][:][0 ] != b'DisplacementFieldTransform_float_3_3' :
65
+ msg = 'Unknown transform type [2]\n '
66
+ for i in h ['TransformGroup' ].keys ():
67
+ msg += f'[{ i } ]: { h ["TransformGroup" ][i ]["TransformType" ][:][0 ]} \n '
68
+ raise ValueError (msg )
69
+ if not np .array_equal (transform2 ['TransformFixedParameters' ], FIXED_PARAMS ):
70
+ msg = 'Unexpected fixed parameters\n '
71
+ msg += f'Expected: { FIXED_PARAMS } \n '
72
+ msg += f'Found: { transform2 ["TransformFixedParameters" ][:]} '
73
+ raise ValueError (msg )
81
74
warp = h ['TransformGroup' ]['2' ]['TransformParameters' ][:]
82
75
warp = warp .reshape ((193 , 229 , 193 , 3 )).transpose (2 , 1 , 0 , 3 )
83
76
warp *= np .array ([- 1 , - 1 , 1 ])
0 commit comments