Skip to content

Commit 8ecb862

Browse files
committed
enh: "densify" voxel-wise nonlinear mappings with interpolation
Interpolate coordinates when the coordinates to be mapped fall off-grid of the field data array. Closes: #155.
1 parent ef5a28f commit 8ecb862

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

nitransforms/nonlinear.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
SpatialReference,
2222
_as_homogeneous,
2323
)
24+
from scipy.ndimage import map_coordinates
2425

2526

2627
class DenseFieldTransform(TransformBase):
@@ -145,10 +146,19 @@ def map(self, x, inverse=False):
145146
raise NotImplementedError
146147
ijk = self.reference.index(x)
147148
indexes = np.round(ijk).astype("int")
148-
if np.any(np.abs(ijk - indexes) > 0.05):
149-
warnings.warn("Some coordinates are off-grid of the field.")
150-
indexes = tuple(tuple(i) for i in indexes.T)
151-
return self._field[indexes]
149+
150+
if np.all(np.abs(ijk - indexes) < 1e-3):
151+
indexes = tuple(tuple(i) for i in indexes.T)
152+
return self._field[indexes]
153+
154+
return map_coordinates(
155+
self._field,
156+
ijk,
157+
order=3,
158+
mode="constant",
159+
cval=np.zeros(self.reference.ndim),
160+
prefilter=True,
161+
)
152162

153163
def __matmul__(self, b):
154164
"""

0 commit comments

Comments
 (0)