@@ -115,10 +115,13 @@ def resample_from_to(from_img,
115
115
to_vox_map ,
116
116
order = 3 ,
117
117
mode = 'constant' ,
118
- cval = 0. ,
118
+ cval = 0. ,
119
119
out_class = Nifti1Image ):
120
120
""" Resample image `from_img` to mapped voxel space `to_vox_map`
121
121
122
+ Resample using N-d spline interpolation (where N is given by the `order`
123
+ argument).
124
+
122
125
Parameters
123
126
----------
124
127
from_img : object
@@ -168,17 +171,17 @@ def resample_from_to(from_img,
168
171
rzs ,
169
172
trans ,
170
173
to_shape ,
171
- order = order ,
172
- mode = mode ,
173
- cval = cval )
174
+ order = order ,
175
+ mode = mode ,
176
+ cval = cval )
174
177
return out_class (data , to_affine , from_img .header )
175
178
176
179
177
180
def resample_to_output (in_img ,
178
- voxel_sizes = None ,
181
+ voxel_sizes = None ,
179
182
order = 3 ,
180
183
mode = 'constant' ,
181
- cval = 0. ,
184
+ cval = 0. ,
182
185
out_class = Nifti1Image ):
183
186
""" Resample image `in_img` to output voxel axes (world space)
184
187
@@ -190,15 +193,16 @@ def resample_to_output(in_img,
190
193
an image from data, affine and header.
191
194
voxel_sizes : None or sequence
192
195
Gives the diagonal entries of ``out_img.affine` (except the trailing 1
193
- for the homogenous coordinates) (``out_img.affine == np.diag(voxel_sizes
194
- + [1])``). If None, return identity `out_img.affine`.
196
+ for the homogenous coordinates) (``out_img.affine ==
197
+ np.diag(voxel_sizes + [1])``). If None, return identity
198
+ `out_img.affine`.
195
199
order : int, optional
196
200
The order of the spline interpolation, default is 3. The order has to
197
201
be in the range 0-5 (see ``scipy.ndimage.affine_transform``).
198
202
mode : str, optional
199
- Points outside the boundaries of the input are filled according
200
- to the given mode ('constant', 'nearest', 'reflect' or 'wrap').
201
- Default is 'constant' (see ``scipy.ndimage.affine_transform``).
203
+ Points outside the boundaries of the input are filled according to the
204
+ given mode ('constant', 'nearest', 'reflect' or 'wrap'). Default is
205
+ 'constant' (see ``scipy.ndimage.affine_transform``).
202
206
cval : scalar, optional
203
207
Value used for points outside the boundaries of the input if
204
208
``mode='constant'``. Default is 0.0 (see
@@ -219,11 +223,11 @@ def resample_to_output(in_img,
219
223
# looks like when resampled into world coordinates
220
224
in_shape = in_img .shape
221
225
n_dim = len (in_shape )
222
- if n_dim < 3 : # Expand image to 3D, make voxel sizes match
226
+ if n_dim < 3 : # Expand image to 3D, make voxel sizes match
223
227
new_shape = in_shape + (1 ,) * (3 - n_dim )
224
- data = in_img .get_data ().reshape (new_shape ) # 2D data should be small
228
+ data = in_img .get_data ().reshape (new_shape ) # 2D data should be small
225
229
in_img = out_class (data , in_img .affine , in_img .header )
226
- if not voxel_sizes is None and len (voxel_sizes ) == n_dim :
230
+ if voxel_sizes is not None and len (voxel_sizes ) == n_dim :
227
231
# Need to pad out voxel sizes to match new image dimensions
228
232
voxel_sizes = tuple (voxel_sizes ) + (1 ,) * (3 - n_dim )
229
233
out_vox_map = vox2out_vox ((in_img .shape , in_img .affine ), voxel_sizes )
@@ -232,8 +236,8 @@ def resample_to_output(in_img,
232
236
233
237
def smooth_image (img ,
234
238
fwhm ,
235
- mode = 'nearest' ,
236
- cval = 0. ,
239
+ mode = 'nearest' ,
240
+ cval = 0. ,
237
241
out_class = Nifti1Image ):
238
242
""" Smooth image `img` along voxel axes by FWHM `fwhm` millimeters
239
243
@@ -291,6 +295,6 @@ def smooth_image(img,
291
295
# Do the smoothing
292
296
sm_data = spnd .gaussian_filter (img .dataobj ,
293
297
vox_sd ,
294
- mode = mode ,
295
- cval = cval )
298
+ mode = mode ,
299
+ cval = cval )
296
300
return out_class (sm_data , img .affine , img .header )
0 commit comments