@@ -259,6 +259,15 @@ def apply(
259
259
slightly blurred if *order > 1*, unless the input is prefiltered,
260
260
i.e. it is the result of calling the spline filter on the original
261
261
input.
262
+ output_dtype: dtype specifier, optional
263
+ The dtype of the returned array or image, if specified.
264
+ If ``None``, the default behavior is to use the effective dtype of
265
+ the input image. If slope and/or intercept are defined, the effective
266
+ dtype is float64, otherwise it is equivalent to the input image's
267
+ ``get_data_dtype()`` (on-disk type).
268
+ If ``reference`` is defined, then the return value is an image, with
269
+ a data array of the effective dtype but with the on-disk dtype set to
270
+ the input image's on-disk dtype.
262
271
263
272
Returns
264
273
-------
@@ -279,11 +288,7 @@ def apply(
279
288
if isinstance (spatialimage , (str , Path )):
280
289
spatialimage = _nbload (str (spatialimage ))
281
290
282
- data = np .asanyarray (
283
- spatialimage .dataobj ,
284
- dtype = spatialimage .get_data_dtype ()
285
- )
286
- output_dtype = output_dtype or data .dtype
291
+ data = np .asanyarray (spatialimage .dataobj )
287
292
targets = ImageGrid (spatialimage ).index ( # data should be an image
288
293
_as_homogeneous (self .map (_ref .ndcoords .T ), dim = _ref .ndim )
289
294
)
@@ -302,9 +307,9 @@ def apply(
302
307
hdr = None
303
308
if _ref .header is not None :
304
309
hdr = _ref .header .copy ()
305
- hdr .set_data_dtype (output_dtype )
310
+ hdr .set_data_dtype (output_dtype or spatialimage . get_data_dtype () )
306
311
moved = spatialimage .__class__ (
307
- resampled .reshape (_ref .shape ). astype ( output_dtype ) ,
312
+ resampled .reshape (_ref .shape ),
308
313
_ref .affine ,
309
314
hdr ,
310
315
)
0 commit comments