From b357538c051c043781c5333ffeae3662533a594a Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Fri, 6 Oct 2017 12:21:33 +0100 Subject: [PATCH] Image class makes sure its header dtype is correct, because this is not done for us when a new nibabel image is created from an array+existing header --- fsl/data/image.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fsl/data/image.py b/fsl/data/image.py index c85d3ab61..7a1000540 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): -- GitLab