Skip to content

Commit

Permalink
FIX: Revert to proportional shift, rounding offset
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Jun 17, 2017
1 parent ba5f8d6 commit 2e9d7e8
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions fmriprep/interfaces/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,11 @@ def _run_interface(self, runtime):

if resize:
# The shift is applied after scaling.
# Apply a shift of half of the new voxels in each direction, to keep the
# origin in the same position relative to the center of the dataset
# Use a proportional shift to maintain relative position in dataset
size_factor = (target_shape.astype(float) + shape) / (2 * shape)
# Use integer shifts to avoid unnecessary interpolation
shift = (target_shape - shape) // 2
sign = np.sign(img.affine[:3, 3])
target_affine[:3, 3] = img.affine[:3, 3] + (shift * sign)
offset = (img.affine[:3, 3] * size_factor - img.affine[:3, 3]).astype(int)
target_affine[:3, 3] = img.affine[:3, 3] + offset
else:
target_affine[:3, 3] = img.affine[:3, 3]

Expand Down

0 comments on commit 2e9d7e8

Please sign in to comment.