|
13 | 13 | TransformFileError,
|
14 | 14 | )
|
15 | 15 |
|
16 |
| -LPS = np.diag([-1, -1, 1, 1]) |
17 |
| - |
18 |
| -class X5LinearTransform(LinearParameters): |
| 16 | +class X5Transform: |
19 | 17 | """A string-based structure for X5 linear transforms."""
|
20 | 18 |
|
21 |
| - template_dtype = np.dtype( |
22 |
| - [ |
23 |
| - ("type", "i4"), |
24 |
| - ("index", "i4"), |
25 |
| - ("parameters", "f8", (4, 4)), |
26 |
| - ("offset", "f4", 3), # Center of rotation |
27 |
| - ] |
28 |
| - ) |
29 |
| - dtype = template_dtype |
| 19 | + _transform = None |
30 | 20 |
|
31 | 21 | def __init__(self, parameters=None, offset=None):
|
32 | 22 | return
|
33 | 23 |
|
34 | 24 | def __str__(self):
|
35 | 25 | return
|
36 | 26 |
|
37 |
| - def to_filename(self, filename): |
38 |
| - '''store this transform to a file with the X5 format''' |
39 |
| - sa = self.structarr |
40 |
| - affine = '''some affine that will return a 4x4 array''' |
41 |
| - return |
42 |
| - |
43 | 27 | @classmethod
|
44 | 28 | def from_filename(cls, filename):
|
45 | 29 | """Read the struct from a X5 file given its path."""
|
46 | 30 | if str(filename).endswith(".h5"):
|
47 |
| - with H5File(str(filename)) as f: |
48 |
| - return cls.from_h5obj(f) |
| 31 | + with H5File(str(filename), 'r') as hdf: |
| 32 | + return cls.from_h5obj(hdf) |
| 33 | + |
| 34 | + @classmethod |
| 35 | + def from_h5obj(cls, h5obj): |
| 36 | + """Read the transformations in an X5 file.""" |
| 37 | + xfm_list = list(h5obj.keys()) |
| 38 | + |
| 39 | + xfm = xfm_list["Transform"] |
| 40 | + inv = xfm_list["Inverse"] |
| 41 | + coords = xfm_list["Size"] |
| 42 | + map = xfm_list["Mapping"] |
| 43 | + |
| 44 | + return xfm, inv, coords, map |
| 45 | + |
49 | 46 |
|
50 | 47 | class X5LinearTransformArray(BaseLinearTransformList):
|
51 | 48 | """A string-based structure for series of X5 linear transforms."""
|
52 | 49 |
|
53 |
| - _inner_type = X5LinearTransform |
| 50 | + _inner_type = X5Transform |
54 | 51 |
|
55 | 52 | @property
|
56 | 53 | def xforms(self):
|
57 |
| - """Get the list of internal ITKLinearTransforms.""" |
| 54 | + """Get the list of internal X5LinearTransforms.""" |
58 | 55 | return self._xforms
|
0 commit comments