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
62df0964
Commit
62df0964
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Cleaned up fnirt module, little changes to bet/flirt
parent
e2bc373b
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
fsl/wrappers/bet.py
+2
-4
2 additions, 4 deletions
fsl/wrappers/bet.py
fsl/wrappers/flirt.py
+2
-4
2 additions, 4 deletions
fsl/wrappers/flirt.py
fsl/wrappers/fnirt.py
+67
-159
67 additions, 159 deletions
fsl/wrappers/fnirt.py
with
71 additions
and
167 deletions
fsl/wrappers/bet.py
+
2
−
4
View file @
62df0964
...
...
@@ -16,10 +16,8 @@ from . import wrapperutils as wutils
@wutils.fileOrImage
(
'
input
'
,
'
output
'
)
def
bet
(
input
,
output
,
**
kwargs
):
"""
Delete non-brain tissue from an image of the whole hea
d.
"""
Wrapper for the ``bet`` comman
d.
:arg input: Image to be brain-extracted
:arg output: Output image
:arg mask: Generate a brain mask
:arg seg: If ``False``, a brain extracted image is not
generated.
...
...
@@ -45,7 +43,7 @@ def bet(input, output, **kwargs):
}
cmd
=
[
'
bet
'
,
input
,
output
]
cmd
+=
wutils
.
applyArgStyle
(
'
-
'
,
argmap
,
valmap
,
**
kwargs
)
cmd
+=
wutils
.
applyArgStyle
(
'
-
'
,
argmap
=
argmap
,
valmap
=
valmap
,
**
kwargs
)
return
run
.
runfsl
(
*
cmd
)
...
...
This diff is collapsed.
Click to expand it.
fsl/wrappers/flirt.py
+
2
−
4
View file @
62df0964
...
...
@@ -28,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
):
"""
Wrapper
around
the ``flirt`` command.
"""
"""
Wrapper
for
the ``flirt`` command.
"""
asrt
.
assertIsNifti
(
src
,
ref
)
...
...
@@ -43,8 +43,6 @@ def flirt(src, ref, **kwargs):
'
noresampblur
'
:
wutils
.
SHOW_IF_TRUE
,
'
2D
'
:
wutils
.
SHOW_IF_TRUE
,
'
v
'
:
wutils
.
SHOW_IF_TRUE
,
'
version
'
:
wutils
.
SHOW_IF_TRUE
,
'
help
'
:
wutils
.
SHOW_IF_TRUE
,
}
cmd
=
[
'
flirt
'
,
'
-in
'
,
src
,
'
-ref
'
,
ref
]
...
...
@@ -93,7 +91,7 @@ def concatxfm(inmat1, inmat2, outmat):
@wutils.fileOrImage
(
'
infile
'
,
'
out
'
,
'
reffile
'
)
@wutils.fileOrArray
(
'
init
'
)
def
mcflirt
(
infile
,
**
kwargs
):
"""
Wrapper
around
the ``mcflirt`` command.
"""
"""
Wrapper
for
the ``mcflirt`` command.
"""
asrt
.
assertIsNifti
(
infile
)
...
...
This diff is collapsed.
Click to expand it.
fsl/wrappers/fnirt.py
+
67
−
159
View file @
62df0964
...
...
@@ -19,182 +19,90 @@ non-linear registration of 3D images.
"""
import
os.path
as
op
import
glob
import
fsl.utils.run
as
run
import
fsl.utils.assertions
as
asrt
from
.
import
wrapperutils
as
wutils
@wutils.fileOrImage
(
'
src
'
,
'
ref
'
,
'
inwarp
'
,
'
cout
'
,
'
iout
'
,
'
fout
'
,
'
jout
'
,
'
refout
'
,
'
refmask
'
,
'
inmask
'
)
@wutils.fileOrArray
(
'
aff
'
)
def
fnirt
(
src
,
ref
,
**
kwargs
):
"""
Wrapper for the ``fnirt`` command.
"""
def
fnirt
(
src
,
ref
,
aff
=
None
,
imprefm
=
None
,
impinm
=
None
,
applyrefmask
=
None
,
applyinmask
=
None
,
subsamp
=
None
,
miter
=
None
,
infwhm
=
None
,
reffwhm
=
None
,
lmbda
=
None
,
estint
=
None
,
warpres
=
None
,
ssqlambda
=
None
,
regmod
=
None
,
intmod
=
None
,
intorder
=
None
,
biasres
=
None
,
biaslambda
=
None
,
refderiv
=
None
,
cout
=
None
,
intout
=
None
,
refout
=
None
,
iout
=
None
,
interp
=
None
,
inwarp
=
None
,
minmet
=
None
,
verbose
=
False
,
intin
=
None
,
jout
=
None
):
"""
Do nonlinear image registration.
"""
cmd
=
'
fnirt --in={0} --ref={1}
'
.
format
(
src
,
ref
)
if
aff
is
not
None
:
cmd
+=
"
--aff={0}
"
.
format
(
aff
)
if
imprefm
is
not
None
:
cmd
+=
"
--imprefm={0}
"
.
format
(
imprefm
)
if
impinm
is
not
None
:
cmd
+=
"
--impinm={0}
"
.
format
(
impinm
)
if
applyrefmask
is
not
None
:
cmd
+=
"
--applyrefmask={0}
"
.
format
(
applyrefmask
)
if
applyinmask
is
not
None
:
cmd
+=
"
--applyinmask={0}
"
.
format
(
applyinmask
)
if
subsamp
is
not
None
:
cmd
+=
"
--subsamp={0}
"
.
format
(
subsamp
)
if
miter
is
not
None
:
cmd
+=
"
--miter={0}
"
.
format
(
miter
)
if
infwhm
is
not
None
:
cmd
+=
"
--infwhm={0}
"
.
format
(
infwhm
)
if
reffwhm
is
not
None
:
cmd
+=
"
--reffwhm={0}
"
.
format
(
reffwhm
)
if
lmbda
is
not
None
:
cmd
+=
"
--lambda={0}
"
.
format
(
lmbda
)
if
estint
is
not
None
:
cmd
+=
"
--estint={0}
"
.
format
(
estint
)
if
warpres
is
not
None
:
cmd
+=
"
--warpres={0}
"
.
format
(
warpres
)
if
ssqlambda
is
not
None
:
cmd
+=
"
--ssqlambda={0}
"
.
format
(
ssqlambda
)
if
regmod
is
not
None
:
cmd
+=
"
--regmod={0}
"
.
format
(
regmod
)
if
intmod
is
not
None
:
cmd
+=
"
--intmod={0}
"
.
format
(
intmod
)
if
intorder
is
not
None
:
cmd
+=
"
--intorder={0}
"
.
format
(
intorder
)
if
biasres
is
not
None
:
cmd
+=
"
--biasres={0}
"
.
format
(
biasres
)
if
biaslambda
is
not
None
:
cmd
+=
"
--biaslambda={0}
"
.
format
(
biaslambda
)
if
refderiv
is
not
None
:
cmd
+=
"
--refderiv={0}
"
.
format
(
refderiv
)
if
cout
is
not
None
:
cmd
+=
"
--cout={0}
"
.
format
(
cout
)
if
intout
is
not
None
:
cmd
+=
"
--intout={0}
"
.
format
(
intout
)
if
refout
is
not
None
:
cmd
+=
"
--refout={0}
"
.
format
(
refout
)
if
iout
is
not
None
:
cmd
+=
"
--iout={0}
"
.
format
(
iout
)
if
interp
is
not
None
:
cmd
+=
"
--interp={0}
"
.
format
(
interp
)
if
inwarp
is
not
None
:
cmd
+=
"
--inwarp={0}
"
.
format
(
inwarp
)
if
minmet
is
not
None
:
cmd
+=
"
--minmet={0}
"
.
format
(
minmet
)
if
intin
is
not
None
:
cmd
+=
"
--intin={0}
"
.
format
(
intin
)
if
jout
is
not
None
:
cmd
+=
"
--jout={0}
"
.
format
(
jout
)
if
verbose
:
cmd
+=
"
--verbose
"
asrt
.
assertIsNifti
(
src
,
ref
)
cmd
=
[
'
fnirt
'
,
'
--in={}
'
.
format
(
src
),
'
--ref={}
'
.
format
(
ref
)]
cmd
+=
wutils
.
applyArgStyle
(
'
--=
'
,
**
kwargs
)
return
run
.
runfsl
(
cmd
)
def
applywarp
(
src
,
ref
,
out
,
warp
=
None
,
premat
=
None
,
prematdir
=
None
,
postmat
=
None
,
postmatdir
=
None
,
interp
=
"
spline
"
,
paddingsize
=
None
,
abs
=
False
,
rel
=
False
):
"""
Tool for applying FSL warps.
The ``prematdir`` and ``postmatdir`` arguments can be used when warping a
4D image. You can specify a directory containing multiple affines, named
``MAT_????`` (as output by e.g. ``mcflirt``). Each file will be applied to
one volume (in order) of the image.
"""
assert
(
warp
or
premat
or
postmat
or
prematdir
or
postmatdir
),
\
"
either a warp or mat (premat, postmat or prematdir) must be supplied
"
assert
not
(
premat
and
prematdir
),
\
"
cannot use premat and prematdir arguments together
"
assert
not
(
postmat
and
postmatdir
),
\
"
cannot use postmat and postmatdir arguments together
"
def
catmats
(
matdir
,
out
):
"""
Concatenate FSL trasformations files into a single file.
"""
mats
=
sorted
(
glob
.
glob
(
op
.
join
(
matdir
,
"
MAT_????
"
)))
with
open
(
out
,
'
w
'
)
as
outfile
:
for
fname
in
mats
:
with
open
(
fname
)
as
infile
:
outfile
.
write
(
infile
.
read
())
cmd
=
"
--in={0} --ref={1} --out={2} --interp={3}
"
.
format
(
src
,
ref
,
out
,
interp
)
cmd
=
"
applywarp
"
+
cmd
if
prematdir
:
premat
=
op
.
join
(
prematdir
,
'
allmats.txt
'
)
catmats
(
prematdir
,
premat
)
if
postmatdir
:
postmat
=
op
.
join
(
postmatdir
,
'
allmats.txt
'
)
catmats
(
postmatdir
,
postmat
)
if
warp
:
cmd
+=
"
--warp={0}
"
.
format
(
warp
)
if
premat
:
cmd
+=
"
--premat={0}
"
.
format
(
premat
)
if
postmat
:
cmd
+=
"
--postmat={0}
"
.
format
(
postmat
)
if
paddingsize
:
cmd
+=
"
--paddingsize={0}
"
.
format
(
paddingsize
)
if
abs
:
cmd
+=
"
--abs
"
if
rel
:
cmd
+=
"
--rel
"
@wutils.fileOrImage
(
'
src
'
,
'
ref
'
,
'
out
'
,
'
warp
'
,
'
mask
'
)
@wutils.fileOrArray
(
'
premat
'
,
'
postmat
'
)
def
applywarp
(
src
,
ref
,
out
,
warp
,
**
kwargs
):
"""
Wrapper for the ``applywarp`` command.
"""
valmap
=
{
'
abs
'
:
wutils
.
SHOW_IF_TRUE
,
'
rel
'
:
wutils
.
SHOW_IF_TRUE
,
'
super
'
:
wutils
.
SHOW_IF_TRUE
,
'
debug
'
:
wutils
.
SHOW_IF_TRUE
,
'
verbose
'
:
wutils
.
SHOW_IF_TRUE
,
}
cmd
=
[
'
applywarp
'
,
'
--in={}
'
.
format
(
src
),
'
--ref={}
'
.
format
(
ref
),
'
--out={}
'
.
format
(
out
),
'
--warp={}
'
.
format
(
warp
)]
cmd
+=
wutils
.
applyArgStyle
(
'
--=
'
,
valmap
=
valmap
,
**
kwargs
)
return
run
.
runfsl
(
cmd
)
def
invwarp
(
inwarp
,
ref
,
outwarp
):
"""
Tool for inverting FSL warps.
"""
@wutils.fileOrImage
(
'
warp
'
,
'
ref
'
,
'
out
'
)
def
invwarp
(
warp
,
ref
,
out
,
**
kwargs
):
"""
Wrapper for the ``invwarp`` command.
"""
valmap
=
{
'
abs
'
:
wutils
.
SHOW_IF_TRUE
,
'
rel
'
:
wutils
.
SHOW_IF_TRUE
,
'
noconstraint
'
:
wutils
.
SHOW_IF_TRUE
,
'
debug
'
:
wutils
.
SHOW_IF_TRUE
,
'
verbose
'
:
wutils
.
SHOW_IF_TRUE
,
}
asrt
.
assertIsNifti
(
warp
,
ref
,
out
)
asrt
.
assertFileExists
(
inwarp
,
ref
)
asrt
.
assertIsNifti
(
inwarp
,
ref
,
outwarp
)
cmd
=
[
'
invwarp
'
,
'
--warp={}
'
.
format
(
warp
),
'
--ref={}
'
.
format
(
ref
),
'
--out={}
'
.
format
(
out
)]
cmd
=
'
invwarp
'
cmd
+=
'
--warp={}
'
.
format
(
inwarp
)
cmd
+=
'
--out={}
'
.
format
(
outwarp
)
cmd
+=
'
--ref={}
'
.
format
(
ref
)
cmd
+=
wutils
.
applyArgStyle
(
'
--=
'
,
valmap
=
valmap
,
**
kwargs
)
return
run
.
runfsl
(
cmd
)
def
convertwarp
(
out
,
ref
,
warp1
=
None
,
warp2
=
None
,
premat
=
None
,
midmat
=
None
,
postmat
=
None
,
shiftmap
=
None
,
shiftdir
=
None
,
absout
=
False
,
abs
=
False
,
rel
=
False
,
relout
=
False
):
"""
Tool for converting FSL warps.
"""
assert
(
warp1
or
warp2
or
premat
or
midmat
or
postmat
),
\
"
either a warp (warp1 or warp2) or mat (premat, midmat, or
"
+
\
"
postmat) must be supplied
"
cmd
=
"
convertwarp --ref={0} --out={1}
"
.
format
(
ref
,
out
)
if
warp1
:
cmd
=
cmd
+
"
--warp1={0}
"
.
format
(
warp1
)
if
warp2
:
cmd
=
cmd
+
"
--warp2={0}
"
.
format
(
warp2
)
if
premat
:
cmd
=
cmd
+
"
--premat={0}
"
.
format
(
premat
)
if
midmat
:
cmd
=
cmd
+
"
--midmat={0}
"
.
format
(
midmat
)
if
postmat
:
cmd
=
cmd
+
"
--postmat={0}
"
.
format
(
postmat
)
if
shiftmap
:
cmd
=
cmd
+
"
--shiftmap={0}
"
.
format
(
shiftmap
)
if
shiftdir
:
cmd
=
cmd
+
"
--shiftdir={0}
"
.
format
(
shiftdir
)
if
absout
:
cmd
=
cmd
+
"
--absout
"
if
relout
:
cmd
=
cmd
+
"
--relout
"
if
abs
:
cmd
=
cmd
+
"
--abs
"
if
rel
:
cmd
=
cmd
+
"
--rel
"
@wutils.fileOrImage
(
'
out
'
,
'
ref
'
,
'
warp1
'
,
'
warp2
'
,
'
shiftmap
'
)
@wutils.fileOrArray
(
'
premat
'
,
'
midmat
'
,
'
postmat
'
)
def
convertwarp
(
out
,
ref
,
**
kwargs
):
"""
Wrapper for the ``convertwarp`` command.
"""
valmap
=
{
'
abs
'
:
wutils
.
SHOW_IF_TRUE
,
'
rel
'
:
wutils
.
SHOW_IF_TRUE
,
'
absout
'
:
wutils
.
SHOW_IF_TRUE
,
'
relout
'
:
wutils
.
SHOW_IF_TRUE
,
'
jacobian
'
:
wutils
.
SHOW_IF_TRUE
,
'
jstats
'
:
wutils
.
SHOW_IF_TRUE
,
'
constrainj
'
:
wutils
.
SHOW_IF_TRUE
,
'
verbose
'
:
wutils
.
SHOW_IF_TRUE
,
}
cmd
=
[
'
convertwarp
'
,
'
--ref={}
'
.
format
(
ref
),
'
--out={}
'
.
format
(
out
)]
cmd
+=
wutils
.
applyArgStyle
(
'
--=
'
,
valmap
=
valmap
,
**
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