Skip to content
Snippets Groups Projects
Commit b357538c authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

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
parent 2f9bf65f
No related branches found
No related tags found
No related merge requests found
...@@ -788,6 +788,15 @@ class Image(Nifti): ...@@ -788,6 +788,15 @@ class Image(Nifti):
indexed = False indexed = False
threaded = 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 # The image parameter may be the name of an image file
if isinstance(image, six.string_types): if isinstance(image, six.string_types):
...@@ -826,6 +835,12 @@ class Image(Nifti): ...@@ -826,6 +835,12 @@ class Image(Nifti):
if header is None: if header is None:
ctr = nib.nifti1.Nifti1Image 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, # But if a nibabel header has been provided,
# we use the corresponding image type # we use the corresponding image type
if isinstance(header, nib.nifti2.Nifti2Header): if isinstance(header, nib.nifti2.Nifti2Header):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment