Skip to content

Commit dee3b30

Browse files
authored
Merge pull request #43 from yhuang43/master
fix voxel-size bug in surfa.image.framed.reorient()
2 parents e266bfb + fcd1f5b commit dee3b30

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

surfa/image/framed.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,19 @@ def reorient(self, orientation, copy=True):
474474
world_axes_trg = get_world_axes(trg_matrix[:self.basedim, :self.basedim])
475475
world_axes_src = get_world_axes(src_matrix[:self.basedim, :self.basedim])
476476

477+
voxsize = np.asarray(self.geom.voxsize)
478+
voxsize_swapped = np.ones(self.basedim)
479+
for i in range(self.basedim):
480+
c1 = trg_orientation[i]
481+
for j in range(self.basedim):
482+
c2 = src_orientation[j]
483+
if ((c1 in 'RL' and c2 in 'RL') or
484+
(c1 in 'AP' and c2 in 'AP') or
485+
(c1 in 'SI' and c2 in 'SI')):
486+
voxsize_swapped[i] = voxsize[j]
487+
break
488+
voxsize = voxsize_swapped
489+
477490
# initialize new
478491
data = self.data.copy()
479492
affine = self.geom.vox2world.matrix.copy()
@@ -494,9 +507,6 @@ def reorient(self, orientation, copy=True):
494507
affine[:, i] = - affine[:, i]
495508
affine[:3, 3] = affine[:3, 3] - affine[:3, i] * (data.shape[i] - 1)
496509

497-
# derive new voxel size
498-
voxsize = np.sqrt(np.sum(affine[:self.basedim, :self.basedim] ** 2, axis=0))
499-
500510
# update geometry
501511
target_geom = ImageGeometry(
502512
shape=data.shape[:3],

0 commit comments

Comments
 (0)