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

Fixes for nifti units, and to image initialisation

parent 654999ba
No related branches found
No related tags found
No related merge requests found
...@@ -85,6 +85,19 @@ NIFTI_XFORM_ANALYZE = 5 ...@@ -85,6 +85,19 @@ NIFTI_XFORM_ANALYZE = 5
"""Code which indicates that this is an ANALYZE image, not a NIFTI image. """ """Code which indicates that this is an ANALYZE image, not a NIFTI image. """
# NIFTI unit codes
NIFTI_UNITS_UNKNOWN = 0
NIFTI_UNITS_METER = 1
NIFTI_UNITS_MM = 2
NIFTI_UNITS_MICRON = 3
NIFTI_UNITS_SEC = 8
NIFTI_UNITS_MSEC = 16
NIFTI_UNITS_USEC = 24
NIFTI_UNITS_HZ = 32
NIFTI_UNITS_PPM = 40
NIFTI_UNITS_RADS = 48
# NIFTI file intent codes # NIFTI file intent codes
NIFTI_INTENT_NONE = 0 NIFTI_INTENT_NONE = 0
NIFTI_INTENT_CORREL = 2 NIFTI_INTENT_CORREL = 2
......
...@@ -332,6 +332,10 @@ class Nifti(notifier.Notifier): ...@@ -332,6 +332,10 @@ class Nifti(notifier.Notifier):
def xyzUnits(self): def xyzUnits(self):
"""Returns the NIFTI XYZ dimension unit code. """ """Returns the NIFTI XYZ dimension unit code. """
# analyze images have no unit field
if self.niftiVersion == 0:
return constants.NIFTI_UNITS_MM
# The nibabel get_xyzt_units returns labels, # The nibabel get_xyzt_units returns labels,
# but we want the NIFTI codes. So we use # but we want the NIFTI codes. So we use
# the (undocumented) nifti1.unit_codes field # the (undocumented) nifti1.unit_codes field
...@@ -345,6 +349,10 @@ class Nifti(notifier.Notifier): ...@@ -345,6 +349,10 @@ class Nifti(notifier.Notifier):
def timeUnits(self): def timeUnits(self):
"""Returns the NIFTI time dimension unit code. """ """Returns the NIFTI time dimension unit code. """
# analyze images have no unit field
if self.niftiVersion == 0:
return constants.NIFTI_UNITS_SEC
# See xyzUnits # See xyzUnits
units = self.header.get_xyzt_units()[1] units = self.header.get_xyzt_units()[1]
units = nib.nifti1.unit_codes[units] units = nib.nifti1.unit_codes[units]
...@@ -742,10 +750,20 @@ class Image(Nifti): ...@@ -742,10 +750,20 @@ class Image(Nifti):
# We default to NIFTI1 and not # We default to NIFTI1 and not
# NIFTI2, because the rest of # NIFTI2, because the rest of
# FSL is not yet NIFTI2 compatible. # FSL is not yet NIFTI2 compatible.
nibImage = nib.nifti1.Nifti1Image(image, if header is None:
xform, ctr = nib.nifti1.Nifti1Image
header=header)
# But if a nibabel header has been provided,
# we use the corresponding image type
if isinstance(header, nib.nifti2.Nifti2Header):
ctr = nib.nifti2.Nifti2Image
elif isinstance(header, nib.nifti1.Nifti1Header):
ctr = nib.nifti1.Nifti1Image
elif isinstance(header, nib.analyze.AnalyzeHeader):
ctr = nib.analyze.AnalyzeImage
nibImage = ctr(image, xform, header=header)
# otherwise, we assume that it is a nibabel image # otherwise, we assume that it is a nibabel image
else: else:
...@@ -1026,6 +1044,7 @@ class Image(Nifti): ...@@ -1026,6 +1044,7 @@ class Image(Nifti):
.. note:: Modifying image data will force the entire image to be .. note:: Modifying image data will force the entire image to be
loaded into memory if it has not already been loaded. loaded into memory if it has not already been loaded.
""" """
values = np.array(values)
log.debug('{}: __setitem__ [{} = {}]'.format(self.name, log.debug('{}: __setitem__ [{} = {}]'.format(self.name,
sliceobj, sliceobj,
......
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