diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4ad29971d0ad8acdce7eb7975cdac8e1479860ff..adab3734e2ac1a1b2dff5177049ec9f38fa8816c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -62,6 +62,8 @@ Fixed split. * Fixed some bugs in the :func:`.fslsub.info` and :func:`.fslinfo.wait` functions. +* Fixed the :func:`.DeformationField.transform` method so it works with + a single set of coordinates. 2.8.4 (Monday 2nd March 2020) diff --git a/fsl/transform/nonlinear.py b/fsl/transform/nonlinear.py index daf13adcf35f85995f1b309acf38dc2d6c145d37..77bc212b87d0fc71dfd3f4155fd5ed36a0d12f95 100644 --- a/fsl/transform/nonlinear.py +++ b/fsl/transform/nonlinear.py @@ -251,7 +251,9 @@ class DeformationField(NonLinearTransform): if from_ is None: from_ = self.refSpace if to is None: to = self.srcSpace - coords = np.asanyarray(coords) + coords = np.asanyarray(coords) + outshape = coords.shape + coords = coords.reshape((-1, 3)) # We may need to pre-transform the # coordinates so they are in the @@ -299,7 +301,7 @@ class DeformationField(NonLinearTransform): outcoords = np.full(coords.shape, np.nan) outcoords[voxmask] = disps - return outcoords + return outcoords.reshape(outshape) class CoefficientField(NonLinearTransform): diff --git a/tests/test_transform/test_nonlinear.py b/tests/test_transform/test_nonlinear.py index aaf4e07fec41df2428a7863bae6e8a229a34659a..323b6aff94f3e741221a000c96d051fb367476b9 100644 --- a/tests/test_transform/test_nonlinear.py +++ b/tests/test_transform/test_nonlinear.py @@ -205,6 +205,10 @@ def test_DeformationField_transform(): got = absfield.transform(rcoords) assert np.all(np.isclose(got, scoords)) + # test single set of coords + got = absfield.transform(rcoords[0]) + assert np.all(np.isclose(got, scoords[0])) + got = relfield.transform(rvoxels, from_='voxel', to='voxel') assert np.all(np.isclose(got, svoxels)) got = absfield.transform(rvoxels, from_='voxel', to='voxel')