Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSL
fslpy
Commits
98a8d42c
Commit
98a8d42c
authored
4 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/transform/fnirt.py
+27
-17
27 additions, 17 deletions
fsl/transform/fnirt.py
with
27 additions
and
17 deletions
fsl/transform/fnirt.py
+
27
−
17
View file @
98a8d42c
...
@@ -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
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment