Skip to content

Commit e7fdd57

Browse files
committed
fix: address code review comments
1 parent cf6d6a0 commit e7fdd57

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

niworkflows/utils/images.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,20 @@ def resample_by_spacing(in_file, zooms, order=3, clip=True, smooth=False):
195195
)
196196

197197
if smooth:
198+
from numbers import Integral
198199
from scipy.ndimage import gaussian_filter
199-
data = gaussian_filter(in_file.get_fdata(),
200-
2 if smooth is True else smooth).astype(dtype)
200+
if smooth is True:
201+
factors = (
202+
np.asarray(in_file.shape[:3], dtype=float)
203+
/ np.asarray(new_size, dtype=float)
204+
)
205+
smooth = np.maximum(0, (factors - 1) / 2)
206+
data = gaussian_filter(in_file.get_fdata(), smooth)
207+
if issubclass(dtype, Integral):
208+
data = np.round(data)
209+
data = data.astype(dtype)
201210
else:
202-
data = np.asanyarray(in_file.dataobj)
211+
data = np.asarray(in_file.dataobj, dtype=dtype)
203212

204213
# Resample data in the new grid
205214
resampled = map_coordinates(

0 commit comments

Comments
 (0)