From 588f2bf8e35f8ce9d4a2524ffac67ef75695ca02 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Tue, 23 Jul 2019 15:19:08 +0100 Subject: [PATCH] RF: applyDeformation supports input image with different FOV to original source image --- fsl/transform/nonlinear.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fsl/transform/nonlinear.py b/fsl/transform/nonlinear.py index 82776bfe6..55fd48ec8 100644 --- a/fsl/transform/nonlinear.py +++ b/fsl/transform/nonlinear.py @@ -745,6 +745,8 @@ def applyDeformation(image, field, ref=None, order=1, mode=None, cval=None): # truncation at the field boundaries, # but there's nothing we can do about # that. + src = field.src + if not field.sameSpace(ref): field = resample.resampleToReference(field, ref, @@ -755,6 +757,21 @@ def applyDeformation(image, field, ref=None, order=1, mode=None, cval=None): else: field = field.data + # If the input image is in a + # different space to the field + # source space, we need to + # adjust the resampling matrix. + # We assume world-world alignment + # between the original source + # and the image to be resampled + if not image.sameSpace(src): + post = affine.concat(image.getAffine('world', 'voxel'), + src .getAffine('voxel', 'world')) + shape = field.shape + field = field.reshape((-1, 3)) + field = affine.transform(field, post) + field = field.reshape(shape) + field = field.transpose((3, 0, 1, 2)) return ndinterp.map_coordinates(image.data, field, -- GitLab