Skip to content

RF: Factor _copy_header, update bias image #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions nipype/interfaces/ants/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,16 +392,21 @@ def _run_interface(self, runtime, correct_return_codes=(0,)):
runtime, correct_return_codes)

if self.inputs.copy_header and runtime.returncode in correct_return_codes:
import nibabel as nb
in_img = nb.load(self.inputs.input_image)
out_file = self._gen_filename('output_image')
out_img = nb.load(out_file, mmap=False)
new_img = out_img.__class__(out_img.get_data(), in_img.affine, in_img.header)
new_img.set_data_dtype(out_img.get_data_dtype())
new_img.to_filename(out_file)
self._copy_header(self._gen_filename('output_image'))
if self.inputs.save_bias or isdefined(self.inputs.bias_image):
self._copy_header(self._gen_filename('bias_image'))

return runtime

def _copy_header(self, fname):
"""Copy header from input image to an output image"""
import nibabel as nb
in_img = nb.load(self.inputs.input_image)
out_img = nb.load(fname, mmap=False)
new_img = out_img.__class__(out_img.get_data(), in_img.affine,
in_img.header)
new_img.set_data_dtype(out_img.get_data_dtype())
new_img.to_filename(fname)


class CorticalThicknessInputSpec(ANTSCommandInputSpec):
Expand Down