|
13 | 13 | from os.path import splitext
|
14 | 14 | import numpy as np
|
15 | 15 |
|
16 |
| -from ..affines import voxel_sizes |
| 16 | +from ..affines import voxel_sizes, from_matvec |
17 | 17 | from ..volumeutils import (array_to_file, array_from_file, Recoder)
|
18 | 18 | from ..spatialimages import HeaderDataError, SpatialImage
|
19 | 19 | from ..fileholders import FileHolder
|
@@ -168,10 +168,8 @@ def get_affine(self):
|
168 | 168 | affine = np.eye(4)
|
169 | 169 | hdr = self._structarr
|
170 | 170 | MdcD = np.hstack((hdr['x_ras'], hdr['y_ras'], hdr['z_ras'])) * hdr['voxelsize']
|
171 |
| - vol_center = MdcD.dot(hdr['dims'][:3].reshape(-1, 1)) / 2 |
172 |
| - affine[:3, :3] = MdcD |
173 |
| - affine[:3, [3]] = hdr['c_ras'] - vol_center |
174 |
| - return affine |
| 171 | + vol_center = MdcD.dot(hdr['dims'][:3]) / 2 |
| 172 | + return from_matvec(MdcD, hdr['c_ras'].T - vol_center) |
175 | 173 |
|
176 | 174 | # For compatibility with nifti (multiple affines)
|
177 | 175 | get_best_affine = get_affine
|
@@ -581,9 +579,7 @@ def _affine2header(self):
|
581 | 579 |
|
582 | 580 | # Assign after we've had a chance to raise exceptions
|
583 | 581 | hdr['voxelsize'] = voxelsize
|
584 |
| - hdr['x_ras'] = Mdc[:, [0]] |
585 |
| - hdr['y_ras'] = Mdc[:, [1]] |
586 |
| - hdr['z_ras'] = Mdc[:, [2]] |
| 582 | + hdr['x_ras'][:, 0], hdr['y_ras'][:, 0], hdr['z_ras'][:, 0] = Mdc.T |
587 | 583 | hdr['c_ras'] = c_ras
|
588 | 584 |
|
589 | 585 |
|
|
0 commit comments