@@ -259,6 +259,15 @@ def apply(
259259 slightly blurred if *order > 1*, unless the input is prefiltered,
260260 i.e. it is the result of calling the spline filter on the original
261261 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.
262271
263272 Returns
264273 -------
@@ -279,11 +288,7 @@ def apply(
279288 if isinstance (spatialimage , (str , Path )):
280289 spatialimage = _nbload (str (spatialimage ))
281290
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 )
287292 targets = ImageGrid (spatialimage ).index ( # data should be an image
288293 _as_homogeneous (self .map (_ref .ndcoords .T ), dim = _ref .ndim )
289294 )
@@ -302,9 +307,9 @@ def apply(
302307 hdr = None
303308 if _ref .header is not None :
304309 hdr = _ref .header .copy ()
305- hdr .set_data_dtype (output_dtype )
310+ hdr .set_data_dtype (output_dtype or spatialimage . get_data_dtype () )
306311 moved = spatialimage .__class__ (
307- resampled .reshape (_ref .shape ). astype ( output_dtype ) ,
312+ resampled .reshape (_ref .shape ),
308313 _ref .affine ,
309314 hdr ,
310315 )
0 commit comments