Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix voxel-size bug in surfa.image.framed.reorient() #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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