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
16bf5ddc
Commit
16bf5ddc
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Cleaned up flirt module
parent
468ac028
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/wrappers/flirt.py
+29
-36
29 additions, 36 deletions
fsl/wrappers/flirt.py
with
29 additions
and
36 deletions
fsl/wrappers/flirt.py
+
29
−
36
View file @
16bf5ddc
#!/usr/bin/env python
#
# flirt.py -
# flirt.py -
Wrappers for FLIRT commands.
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
"""
"""
This module provides wrapper functions for the FSL `FLIRT
<https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FLIRT>`_ tool, and other related
tools.
.. autosummary::
:nosignatures:
flirt
invxfm
applyxfm
invxfm
concatxfm
mcflirt
"""
...
...
@@ -19,7 +21,6 @@
import
fsl.utils.run
as
run
import
fsl.utils.assertions
as
asrt
import
fsl.data.image
as
fslimage
from
.
import
wrapperutils
as
wutils
...
...
@@ -27,7 +28,7 @@ from . import wrapperutils as wutils
@wutils.fileOrImage
(
'
src
'
,
'
ref
'
,
'
out
'
,
'
wmseg
'
,
'
fieldmap
'
,
'
fieldmapmask
'
)
@wutils.fileOrArray
(
'
init
'
,
'
omat
'
,
'
wmcoords
'
,
'
wmnorms
'
)
def
flirt
(
src
,
ref
,
**
kwargs
):
"""
FLIRT (FMRIB
'
s Linear Image Registration Tool).
"""
"""
Wrapper around the ``flirt`` command.
"""
asrt
.
assertIsNifti
(
src
,
ref
)
...
...
@@ -52,30 +53,30 @@ def flirt(src, ref, **kwargs):
return
run
.
runfsl
(
cmd
)
@wutils.fileOrImage
(
'
src
'
,
'
ref
'
,
'
out
'
)
@wutils.fileOrArray
(
'
mat
'
)
def
applyxfm
(
src
,
ref
,
mat
,
out
,
interp
=
'
spline
'
):
"""
Convenience function which runs ``flirt -applyxfm ...``.
"""
return
flirt
(
src
,
ref
,
out
=
out
,
applyxfm
=
True
,
init
=
mat
,
interp
=
interp
)
@wutils.fileOrArray
def
invxfm
(
inmat
,
omat
):
"""
Tool for inverting FSL transformation matrices
.
"""
"""
Use ``convert_xfm`` to invert an affine
.
"""
asrt
.
assertFileExists
(
inmat
)
cmd
=
"
convert_xfm -omat {
0
} -inverse {
1}
"
.
format
(
omat
,
inmat
)
cmd
=
'
convert_xfm -omat {} -inverse {
}
'
.
format
(
omat
,
inmat
)
return
run
.
runfsl
(
cmd
)
def
applyxfm
(
src
,
ref
,
mat
,
out
,
interp
=
'
spline
'
):
"""
Tool for applying FSL transformation matrices.
"""
asrt
.
assertFileExists
(
src
,
ref
)
asrt
.
assertIsNifti
(
src
,
ref
)
cmd
=
"
flirt -init {0} -in {1} -ref {2} -applyxfm -out {3} -interp {4}
"
return
run
.
runfsl
(
cmd
.
format
(
mat
,
src
,
ref
,
out
,
interp
))
@wutils.required
(
'
inmat1
'
,
'
inmat2
'
,
'
outmat
'
)
@wutils.fileOrArray
(
'
inmat1
'
,
'
inmat2
'
,
'
outmat
'
)
def
concatxfm
(
inmat1
,
inmat2
,
outmat
):
"""
Tool to concatenate two FSL transformation matrices.
"""
print
(
'
inmat1
'
,
inmat1
)
print
(
'
inmat2
'
,
inmat2
)
print
(
'
outmat
'
,
outmat
)
"""
Use ``convert_xfm`` to concatenate two affines.
"""
asrt
.
assertFileExists
(
inmat1
,
inmat2
)
...
...
@@ -89,22 +90,14 @@ def concatxfm(inmat1, inmat2, outmat):
return
run
.
runfsl
(
cmd
)
def
mcflirt
(
infile
,
outfile
,
reffile
=
None
,
spline_final
=
True
,
plots
=
True
,
mats
=
True
,
refvol
=
None
):
"""
Rigid-body motion correction using mcflirt.
"""
@wutils.fileOrImage
(
'
infile
'
,
'
out
'
,
'
reffile
'
)
@wutils.fileOrArary
(
'
init
'
)
def
mcflirt
(
infile
,
**
kwargs
):
"""
Wrapper around the ``mcflirt`` command.
"""
outfile
=
fslimage
.
removeExt
(
outfile
)
cmd
=
"
mcflirt -in {0} -out {1} -rmsrel -rmsabs
"
.
format
(
infile
,
outfile
)
asrt
.
assertIsNifti
(
infile
)
if
reffile
is
not
None
:
cmd
+=
"
-reffile {0}
"
.
format
(
reffile
)
if
refvol
is
not
None
:
cmd
+=
"
-refvol {0}
"
.
format
(
refvol
)
if
spline_final
:
cmd
+=
"
-spline_final
"
if
plots
:
cmd
+=
"
-plots
"
if
mats
:
cmd
+=
"
-mats
"
cmd
=
[
'
mcflirt
'
,
'
-in
'
,
infile
]
cmd
+=
wutils
.
applyArgStyle
(
'
-
'
,
**
kwargs
)
return
run
.
runfsl
(
cmd
)
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