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

RF: readFnirt function allows field type to be specified in case file has no

intent code set
parent 79fd9598
No related branches found
No related tags found
No related merge requests found
...@@ -257,7 +257,7 @@ def _readFnirtCoefficientField(fname, img, src, ref): ...@@ -257,7 +257,7 @@ def _readFnirtCoefficientField(fname, img, src, ref):
fieldToRefMat=fieldToRefMat) fieldToRefMat=fieldToRefMat)
def readFnirt(fname, src, ref, defType=None): def readFnirt(fname, src, ref, defType=None, intent=None):
"""Reads a non-linear FNIRT transformation image, returning """Reads a non-linear FNIRT transformation image, returning
a :class:`.DeformationField` or :class:`.CoefficientField` depending a :class:`.DeformationField` or :class:`.CoefficientField` depending
on the file type. on the file type.
...@@ -268,28 +268,38 @@ def readFnirt(fname, src, ref, defType=None): ...@@ -268,28 +268,38 @@ def readFnirt(fname, src, ref, defType=None):
:arg defType: Deformation type - either ``'absolute'`` or ``'relative'``. :arg defType: Deformation type - either ``'absolute'`` or ``'relative'``.
Only used if the file is a deformation field. If not Only used if the file is a deformation field. If not
provided, is automatically inferred from the data. provided, is automatically inferred from the data.
:arg intent: NIFTI intent code of ``fname``. e.g.
:attr:`.constants.FSL_FNIRT_DISPLACEMENT_FIELD`. If not
provided, the intent is read from the image header.
""" """
# Figure out whether the file if defType not in (None, 'absolute', 'relative'):
# is a deformation field or raise ValueError('defType must be None, "absolute" or "relative" '
# a coefficient field '(passed in as {})'.format(defType))
img = fslimage.Image(fname, loadData=False) # Figure out whether the file is a
disps = (constants.FSL_FNIRT_DISPLACEMENT_FIELD, # deformation field or a coefficient
constants.FSL_TOPUP_FIELD) # field by checking the intent code.
coefs = (constants.FSL_CUBIC_SPLINE_COEFFICIENTS, # If the intent is provided, assume
constants.FSL_DCT_COEFFICIENTS, # that the caller knows the type of
constants.FSL_QUADRATIC_SPLINE_COEFFICIENTS, # the field.
constants.FSL_TOPUP_CUBIC_SPLINE_COEFFICIENTS, img = fslimage.Image(fname, loadData=False)
constants.FSL_TOPUP_QUADRATIC_SPLINE_COEFFICIENTS) intent = intent or img.intent
disps = (constants.FSL_FNIRT_DISPLACEMENT_FIELD,
constants.FSL_TOPUP_FIELD)
coefs = (constants.FSL_CUBIC_SPLINE_COEFFICIENTS,
constants.FSL_DCT_COEFFICIENTS,
constants.FSL_QUADRATIC_SPLINE_COEFFICIENTS,
constants.FSL_TOPUP_CUBIC_SPLINE_COEFFICIENTS,
constants.FSL_TOPUP_QUADRATIC_SPLINE_COEFFICIENTS)
if img.intent in disps: if intent in disps:
return _readFnirtDeformationField(fname, img, src, ref, defType) return _readFnirtDeformationField(fname, img, src, ref, defType)
elif img.intent in coefs: elif intent in coefs:
return _readFnirtCoefficientField(fname, img, src, ref) return _readFnirtCoefficientField(fname, img, src, ref)
else: else:
raise ValueError('Cannot determine type of nonlinear ' raise ValueError('Cannot determine type of nonlinear warp field '
'file {}'.format(fname)) '{} (intent code: {})'.format(fname, intent))
def toFnirt(field): def toFnirt(field):
......
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