Skip to content

Commit e56f748

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 f8650e4 commit e56f748

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

nitransforms/nonlinear.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
SpatialReference,
2222
_as_homogeneous,
2323
)
24+
from scipy.ndimage import map_coordinates
25+
2426

2527

2628
class DenseFieldTransform(TransformBase):
@@ -134,8 +136,15 @@ def map(self, x, inverse=False):
134136
raise NotImplementedError
135137
ijk = self.reference.index(x)
136138
indexes = np.round(ijk).astype("int")
137-
if np.any(np.abs(ijk - indexes) > 0.05):
138-
warnings.warn("Some coordinates are off-grid of the displacements field.")
139+
if np.any(np.abs(ijk - indexes) > 1e-3):
140+
return map_coordinates(
141+
self._field,
142+
ijk,
143+
order=3,
144+
mode="constant",
145+
cval=np.zeros(self.reference.ndim),
146+
prefilter=True,
147+
)
139148
indexes = tuple(tuple(i) for i in indexes.T)
140149
return self._field[indexes]
141150

0 commit comments

Comments
 (0)