diff --git a/fsl/data/image.py b/fsl/data/image.py index c85d3ab612a651c165c08e81ae696d6952b0bd5b..7a10005407ed350009f0b3bed3f456112517bca3 100644 --- a/fsl/data/image.py +++ b/fsl/data/image.py @@ -788,6 +788,15 @@ class Image(Nifti): indexed = False threaded = False + # Take a copy of the header if one has + # been provided + # + # NOTE: Nifti extensions are copied by + # reference, which may cause issues in + # the future. + if header is not None: + header = header.copy() + # The image parameter may be the name of an image file if isinstance(image, six.string_types): @@ -826,6 +835,12 @@ class Image(Nifti): if header is None: ctr = nib.nifti1.Nifti1Image + # make sure that the data type is correct, + # in case this header was passed in from + # a different image + if header is not None: + header.set_data_dtype(image.dtype) + # But if a nibabel header has been provided, # we use the corresponding image type if isinstance(header, nib.nifti2.Nifti2Header):