Commit d635bdae authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

If an xform and header are provided, make sure they are consistent.

parent 7b9768fa
......@@ -753,7 +753,9 @@ class Image(Nifti):
coordinates. If not provided, and a ``header`` is
provided, the transformation in the header is used.
If neither a ``xform`` nor a ``header`` are provided,
an identity matrix is used.
an identity matrix is used. If both a ``xform`` and a
``header`` are provided, the ``xform`` is used in
preference to the header transformation.
:arg loadData: If ``True`` (the default) the image data is loaded
in to memory. Otherwise, only the image header
......@@ -799,6 +801,17 @@ class Image(Nifti):
if header is not None:
header = header.copy()
# if a header and xform are provided,
# make sure the xform gets used. Does
# not apply to ANALYZE images,
if header is not None and \
xform is not None and \
isinstance(header, nib.nifti1.Nifti1Header):
sform = int(header.get_sform(True)[1])
qform = int(header.get_qform(True)[1])
header.set_sform(xform, code=sform)
header.set_qform(xform, code=qform)
# The image parameter may be the name of an image file
if isinstance(image, six.string_types):
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment