Skip to content

Commit

Permalink
Merge pull request #41 from mu40/voxsize-from-affine
Browse files Browse the repository at this point in the history
Compute resolution from affine to fix voxel-size bug.
  • Loading branch information
jnolan14 authored Oct 9, 2024
2 parents c80a3de + c2daf2e commit 041905f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions surfa/image/framed.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,6 @@ 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 = voxsize[world_axes_src][world_axes_trg]

# initialize new
data = self.data.copy()
affine = self.geom.vox2world.matrix.copy()
Expand All @@ -497,6 +494,9 @@ 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 041905f

Please sign in to comment.