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

Some fixes to Image class

parent aff196f2
No related branches found
No related tags found
No related merge requests found
...@@ -144,7 +144,7 @@ class Nifti(notifier.Notifier): ...@@ -144,7 +144,7 @@ class Nifti(notifier.Notifier):
if not isinstance(header, nib.analyze.AnalyzeHeader): if not isinstance(header, nib.analyze.AnalyzeHeader):
raise ValueError('Unrecognised header: {}'.format(header)) raise ValueError('Unrecognised header: {}'.format(header))
header = header.copy() header = header
origShape, shape, pixdim = self.__determineShape(header) origShape, shape, pixdim = self.__determineShape(header)
if len(shape) < 3 or len(shape) > 4: if len(shape) < 3 or len(shape) > 4:
...@@ -765,6 +765,23 @@ class Image(Nifti): ...@@ -765,6 +765,23 @@ class Image(Nifti):
coords = [0] * len(self.__nibImage.shape) coords = [0] * len(self.__nibImage.shape)
return self.__nibImage.dataobj[tuple(coords)].dtype return self.__nibImage.dataobj[tuple(coords)].dtype
@Nifti.voxToWorldMat.setter
def voxToWorldMat(self, xform):
"""Overrides the :meth:`Nifti.voxToWorldMat` property setter.
In ``nibabel``, the header and image affines can easily get
out of sync when they are modified. The ``Nifti`` implementation
updates the header, and this implementation makes sure the
image is also updated.
"""
Nifti.voxToWorldMat.fset(self, xform)
xform = self.voxToWorldMat
self.__nibImage.set_sform(xform)
self.__nibImage.set_qform(xform)
def __transformChanged(self, *args, **kwargs): def __transformChanged(self, *args, **kwargs):
"""Called when the ``voxToWorldMat`` of this :class:`Nifti` instance """Called when the ``voxToWorldMat`` of this :class:`Nifti` instance
...@@ -871,6 +888,7 @@ class Image(Nifti): ...@@ -871,6 +888,7 @@ class Image(Nifti):
nib.save(self.__nibImage, filename) nib.save(self.__nibImage, filename)
self.__fileobj.close() self.__fileobj.close()
self.__nibImage, self.__fileobj = loadIndexedImageFile(filename) self.__nibImage, self.__fileobj = loadIndexedImageFile(filename)
self.header = self.__nibImage.get_header()
self.__dataSource = filename self.__dataSource = filename
self.__saveState = True self.__saveState = True
......
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