diff --git a/nitransforms/nonlinear.py b/nitransforms/nonlinear.py index 79c3aa45..69c19d35 100644 --- a/nitransforms/nonlinear.py +++ b/nitransforms/nonlinear.py @@ -170,17 +170,21 @@ def map(self, x, inverse=False): indexes = tuple(tuple(i) for i in indexes.T) return self._field[indexes] - return np.vstack(tuple( + new_map = np.vstack(tuple( map_coordinates( self._field[..., i], ijk.T, order=3, mode="constant", - cval=0, + cval=np.nan, prefilter=True, ) for i in range(self.reference.ndim) )).T + # Set NaN values back to the original coordinates value = no displacement + new_map[np.isnan(new_map)] = x[np.isnan(new_map)] + return new_map + def __matmul__(self, b): """ Compose with a transform on the right.