Skip to content

Commit 5a2fdd1

Browse files
committed
enh: eliminate casting of smoothed data
let ``map_coordinates`` do the trick.
1 parent f803bdd commit 5a2fdd1

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

niworkflows/utils/images.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ def resample_by_spacing(in_file, zooms, order=3, clip=True, smooth=False):
163163
qform, qcode = in_file.get_qform(coded=True)
164164

165165
hdr = in_file.header.copy()
166-
dtype = hdr.get_data_dtype()
167166
zooms = np.array(zooms)
168167

169168
# Calculate the factors to normalize voxel size to the specific zooms
@@ -195,22 +194,18 @@ def resample_by_spacing(in_file, zooms, order=3, clip=True, smooth=False):
195194
)
196195

197196
if smooth:
198-
from numbers import Integral
199197
from scipy.ndimage import gaussian_filter
200198
if smooth is True:
201199
smooth = np.maximum(0, (pre_zooms / zooms - 1) / 2)
202200
data = gaussian_filter(in_file.get_fdata(), smooth)
203-
if issubclass(dtype, Integral):
204-
data = np.round(data)
205-
data = data.astype(dtype)
206201
else:
207-
data = np.asarray(in_file.dataobj, dtype=dtype)
202+
data = np.asarray(in_file.dataobj)
208203

209204
# Resample data in the new grid
210205
resampled = map_coordinates(
211206
data,
212207
ijk[:3, :],
213-
output=dtype,
208+
output=hdr.get_data_dtype(),
214209
order=order,
215210
mode="constant",
216211
cval=0,

0 commit comments

Comments
 (0)