Skip to content

Commit 720809b

Browse files
authored
Merge pull request #4 from effigies/enh/N4-header
RF: Factor _copy_header, update bias image
2 parents 98af18e + d973105 commit 720809b

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

nipype/interfaces/ants/segmentation.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -392,16 +392,21 @@ def _run_interface(self, runtime, correct_return_codes=(0,)):
392392
runtime, correct_return_codes)
393393

394394
if self.inputs.copy_header and runtime.returncode in correct_return_codes:
395-
import nibabel as nb
396-
in_img = nb.load(self.inputs.input_image)
397-
out_file = self._gen_filename('output_image')
398-
out_img = nb.load(out_file, mmap=False)
399-
new_img = out_img.__class__(out_img.get_data(), in_img.affine, in_img.header)
400-
new_img.set_data_dtype(out_img.get_data_dtype())
401-
new_img.to_filename(out_file)
395+
self._copy_header(self._gen_filename('output_image'))
396+
if self.inputs.save_bias or isdefined(self.inputs.bias_image):
397+
self._copy_header(self._gen_filename('bias_image'))
402398

403399
return runtime
404400

401+
def _copy_header(self, fname):
402+
"""Copy header from input image to an output image"""
403+
import nibabel as nb
404+
in_img = nb.load(self.inputs.input_image)
405+
out_img = nb.load(fname, mmap=False)
406+
new_img = out_img.__class__(out_img.get_data(), in_img.affine,
407+
in_img.header)
408+
new_img.set_data_dtype(out_img.get_data_dtype())
409+
new_img.to_filename(fname)
405410

406411

407412
class CorticalThicknessInputSpec(ANTSCommandInputSpec):

0 commit comments

Comments
 (0)