Skip to content

Commit eb097f4

Browse files
committed
copy header from input image in conform
The implementation for `conform` is informed by FreeSurfer: https://github.com/freesurfer/freesurfer/blob/4db941ef298c0ac5fb78c29fd0e95571ac363e16/utils/mri_conform.cpp#L140-L256 In that function, the KeepDC flag is false, so the shorter path in the if-else statement is taken.
1 parent 3658170 commit eb097f4

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

nibabel/processing.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -373,16 +373,15 @@ def conform(from_img,
373373
elif len(voxel_size) != required_ndim:
374374
raise ValueError("`voxel_size` must have {} values".format(required_ndim))
375375

376-
# Create fake image of the image we want to resample to.
377-
hdr = from_img.header_class()
378-
hdr.set_data_shape(out_shape)
379-
hdr.set_zooms(voxel_size)
380-
dst_aff = hdr.get_best_affine()
381-
to_img = from_img.__class__(np.empty(out_shape), affine=dst_aff, header=hdr)
376+
# Create template image to which input is resampled.
377+
tmpl_hdr = from_img.header_class().from_header(from_img.header)
378+
tmpl_hdr.set_data_shape(out_shape)
379+
tmpl_hdr.set_zooms(voxel_size)
380+
tmpl = from_img.__class__(np.empty(out_shape), affine=np.eye(4), header=tmpl_hdr)
382381

383382
# Resample input image.
384383
out_img = resample_from_to(
385-
from_img=from_img, to_vox_map=to_img, order=order, mode="constant",
384+
from_img=from_img, to_vox_map=tmpl, order=order, mode="constant",
386385
cval=cval, out_class=out_class)
387386

388387
# Reorient to desired orientation.

0 commit comments

Comments
 (0)