Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Michiel Cottaar
fslpy
Commits
84300e0c
Commit
84300e0c
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
BF,RF: FIxes to fnirt/x5
parent
f57b0a92
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
fsl/transform/fnirt.py
+17
-12
17 additions, 12 deletions
fsl/transform/fnirt.py
fsl/transform/x5.py
+11
-11
11 additions, 11 deletions
fsl/transform/x5.py
with
28 additions
and
23 deletions
fsl/transform/fnirt.py
+
17
−
12
View file @
84300e0c
...
...
@@ -24,21 +24,24 @@ import fsl.data.constants as constants
log
=
logging
.
getLogger
(
__name__
)
def
_readFnirtDisplacementField
(
fname
,
img
,
src
,
ref
):
def
_readFnirtDisplacementField
(
fname
,
img
,
src
,
ref
,
dispType
=
None
):
"""
Loads ``fname``, assumed to be a FNIRT displacement field.
:arg fname: File name of FNIRT displacement field
:arg img: ``fname`` loaded as an :class:`.Image`
:arg src: Source image
:arg ref: Reference image
:return: A :class:`.DisplacementField`
:arg fname: File name of FNIRT displacement field
:arg img: ``fname`` loaded as an :class:`.Image`
:arg src: Source image
:arg ref: Reference image
:arg dispType: Displacement type - either ``
'
absolute
'
`` or ``
'
relative
'
``.
If not provided, is automatically inferred from the data.
:return: A :class:`.DisplacementField`
"""
from
.
import
nonlinear
return
nonlinear
.
DisplacementField
(
fname
,
src
,
ref
,
srcSpace
=
'
fsl
'
,
refSpace
=
'
fsl
'
)
refSpace
=
'
fsl
'
,
dispType
=
dispType
)
def
_readFnirtCoefficientField
(
fname
,
img
,
src
,
ref
):
...
...
@@ -114,14 +117,16 @@ def _readFnirtCoefficientField(fname, img, src, ref):
fieldToRefMat
=
fieldToRefMat
)
def
readFnirt
(
fname
,
src
,
ref
):
def
readFnirt
(
fname
,
src
,
ref
,
dispType
=
None
):
"""
Reads a non-linear FNIRT transformation image, returning
a :class:`.DisplacementField` or :class:`.CoefficientField` depending
on the file type.
:arg fname: File name of FNIRT transformation
:arg src: Source image
:arg ref: Reference image
:arg fname: File name of FNIRT transformation
:arg src: Source image
:arg ref: Reference image
:arg dispType: Displacement type - either ``
'
absolute
'
`` or ``
'
relative
'
``.
If not provided, is automatically inferred from the data.
"""
# Figure out whether the file
...
...
@@ -139,7 +144,7 @@ def readFnirt(fname, src, ref):
constants
.
FSL_TOPUP_QUADRATIC_SPLINE_COEFFICIENTS
)
if
img
.
intent
in
disps
:
return
_readFnirtDisplacementField
(
fname
,
img
,
src
,
ref
)
return
_readFnirtDisplacementField
(
fname
,
img
,
src
,
ref
,
dispType
)
elif
img
.
intent
in
coefs
:
return
_readFnirtCoefficientField
(
fname
,
img
,
src
,
ref
)
else
:
...
...
This diff is collapsed.
Click to expand it.
fsl/transform/x5.py
+
11
−
11
View file @
84300e0c
...
...
@@ -402,10 +402,10 @@ def readNonLinearX5(fname):
root
=
f
[
'
/
'
]
_validateNonLinearTransform
(
root
)
if
root
[
'
SubType
'
]
==
'
displacement
'
:
field
=
_readDisplacementField
(
root
)
el
if
root
[
'
S
ub
T
ype
'
]
==
'
coefficient
'
:
field
=
_readCoefficientField
(
root
)
subtype
=
root
.
attrs
[
'
SubType
'
]
if
s
ub
t
ype
==
'
displacement
'
:
field
=
_readDisplacementField
(
root
)
elif
subtype
==
'
coefficient
'
:
field
=
_readCoefficientField
(
root
)
return
field
...
...
@@ -484,8 +484,8 @@ def _writeAffine(group, xform):
:arg xform: ``numpy`` array containing a ``(4, 4)`` affine transformation.
"""
xform
=
np
.
asarray
(
xform
,
dtype
=
np
.
float64
)
inv
=
np
.
asarray
(
affine
.
inver
se
(
xform
),
dtype
=
np
.
float64
)
xform
=
np
.
asarray
(
xform
,
dtype
=
np
.
float64
)
inv
=
np
.
asarray
(
affine
.
inver
t
(
xform
),
dtype
=
np
.
float64
)
group
.
attrs
[
'
Type
'
]
=
'
linear
'
group
.
create_dataset
(
'
Transform
'
,
data
=
xform
)
...
...
@@ -624,7 +624,7 @@ def _writeNonLinearCommon(group, field):
_writeAffine
(
group
.
create_group
(
'
Post
'
),
post
)
if
field
.
srcToRefMat
is
not
None
:
_writeAffine
(
group
.
create_group
(
'
InitialAlignment
'
,
field
.
srcToRefMat
)
)
_writeAffine
(
group
.
create_group
(
'
InitialAlignment
'
)
,
field
.
srcToRefMat
)
def
_readDisplacementField
(
group
):
...
...
@@ -674,15 +674,15 @@ def _readCoefficientField(group):
src
,
ref
,
pre
,
post
,
init
,
srcSpace
,
refSpace
=
_readNonLinearCommon
(
group
)
field
=
np
.
array
(
group
[
'
Transform
'
])
ftype
=
group
[
'
Representation
'
]
spacing
=
group
[
'
Parameters
/
Spacing
'
]
ftype
=
group
.
attrs
[
'
Representation
'
]
spacing
=
group
[
'
Parameters
'
].
attrs
[
'
Spacing
'
]
refToField
=
_readAffine
(
group
[
'
Parameters/ReferenceToField
'
])
fieldToRef
=
affine
.
invert
(
refToField
)
if
ftype
==
'
quadratic bspline
'
:
ftype
=
'
quadratic
'
elif
ftype
==
'
cubic bspline
'
:
ftype
=
'
cubic
'
if
spacing
.
shape
!=
3
:
if
spacing
.
shape
!=
(
3
,)
:
raise
X5Error
(
'
Invalid spacing: {}
'
.
format
(
spacing
))
field
=
nonlinear
.
CoefficientField
(
field
,
...
...
@@ -714,7 +714,7 @@ def _writeCoefficientField(group, field):
elif
field
.
fieldType
==
'
quadratic
'
:
group
.
attrs
[
'
Representation
'
]
=
'
quadratic bspline
'
xform
=
np
.
field
.
data
.
astype
(
np
.
float64
)
xform
=
field
.
data
.
astype
(
np
.
float64
)
group
.
create_dataset
(
'
Transform
'
,
data
=
xform
)
...
...
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