Skip to content

Commit

Permalink
Merge pull request #43 from yhuang43/master
Browse files Browse the repository at this point in the history
fix voxel-size bug in surfa.image.framed.reorient()
  • Loading branch information
jnolan14 authored Dec 3, 2024
2 parents e266bfb + fcd1f5b commit dee3b30
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions surfa/image/framed.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,19 @@ def reorient(self, orientation, copy=True):
world_axes_trg = get_world_axes(trg_matrix[:self.basedim, :self.basedim])
world_axes_src = get_world_axes(src_matrix[:self.basedim, :self.basedim])

voxsize = np.asarray(self.geom.voxsize)
voxsize_swapped = np.ones(self.basedim)
for i in range(self.basedim):
c1 = trg_orientation[i]
for j in range(self.basedim):
c2 = src_orientation[j]
if ((c1 in 'RL' and c2 in 'RL') or
(c1 in 'AP' and c2 in 'AP') or
(c1 in 'SI' and c2 in 'SI')):
voxsize_swapped[i] = voxsize[j]
break
voxsize = voxsize_swapped

# initialize new
data = self.data.copy()
affine = self.geom.vox2world.matrix.copy()
Expand All @@ -494,9 +507,6 @@ def reorient(self, orientation, copy=True):
affine[:, i] = - affine[:, i]
affine[:3, 3] = affine[:3, 3] - affine[:3, i] * (data.shape[i] - 1)

# derive new voxel size
voxsize = np.sqrt(np.sum(affine[:self.basedim, :self.basedim] ** 2, axis=0))

# update geometry
target_geom = ImageGeometry(
shape=data.shape[:3],
Expand Down

0 comments on commit dee3b30

Please sign in to comment.