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
7d5e6305
Commit
7d5e6305
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
RF: Handle case where fslmaths wrapper is passed output=LOAD. Fix/clarify
usage docs.
parent
8460b25c
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/wrappers/__init__.py
+2
-2
2 additions, 2 deletions
fsl/wrappers/__init__.py
fsl/wrappers/fslmaths.py
+31
-6
31 additions, 6 deletions
fsl/wrappers/fslmaths.py
with
33 additions
and
8 deletions
fsl/wrappers/__init__.py
+
2
−
2
View file @
7d5e6305
...
@@ -63,11 +63,11 @@ if we want to FLIRT two images and get the result, we can do this::
...
@@ -63,11 +63,11 @@ if we want to FLIRT two images and get the result, we can do this::
Similarly, we can run a ``fslmaths`` command on in-memory images::
Similarly, we can run a ``fslmaths`` command on in-memory images::
import nibabel as nib
import nibabel as nib
from fsl.wrappers import fslmaths
, LOAD
from fsl.wrappers import fslmaths
image = nib.load(
'
image.nii
'
)
image = nib.load(
'
image.nii
'
)
mask = nib.load(
'
mask.nii
'
)
mask = nib.load(
'
mask.nii
'
)
output = fslmaths(image).mas(mask).bin().run(
LOAD
)
output = fslmaths(image).mas(mask).bin().run()
If you are *writing* wrapper functions, take a look at the
If you are *writing* wrapper functions, take a look at the
...
...
This diff is collapsed.
Click to expand it.
fsl/wrappers/fslmaths.py
+
31
−
6
View file @
7d5e6305
...
@@ -13,7 +13,28 @@ from . import wrapperutils as wutils
...
@@ -13,7 +13,28 @@ from . import wrapperutils as wutils
class
fslmaths
(
object
):
class
fslmaths
(
object
):
"""
Perform mathematical manipulation of images.
"""
"""
Perform mathematical manipulation of images.
``fslmaths`` is unlike the other FSL wrapper tools in that it provdes
an object-oriented interface which is hopefully easier to use than
constructing a ``fslmaths`` command-line call. For example, the
following call to the ``fslmaths`` wrapper function::
fslmaths(
'
input.nii
'
).thr(0.25).mul(-1).run(
'
output.nii
'
)
will be translated into the following command-line call::
fslmaths input.nii -thr 0.25 -mul -1 output.nii
The ``fslmaths`` wrapper function can also be used with in-memory
images. If no output file name is passed to the :meth:`run` method, the
result is loaded into memory and returned as a ``nibabel`` image. For
example::
import nibabel as nib
input = nib.load(
'
input.nii
'
)
output = fslmaths(input).thr(0.25).mul(-1).run()
"""
def
__init__
(
self
,
input
):
def
__init__
(
self
,
input
):
"""
Constructor.
"""
"""
Constructor.
"""
...
@@ -138,20 +159,24 @@ class fslmaths(object):
...
@@ -138,20 +159,24 @@ class fslmaths(object):
return
self
return
self
def
run
(
self
,
output
=
None
):
def
run
(
self
,
output
=
None
):
"""
Save output of operations to image.
"""
"""
Save output of operations to image. Set ``output`` to a filename to have
the result saved to file, or omit ``output`` entirely to have the
result returned as a ``nibabel`` image.
"""
cmd
=
[
'
fslmaths
'
,
self
.
__input
]
+
self
.
__args
cmd
=
[
'
fslmaths
'
,
self
.
__input
]
+
self
.
__args
if
output
is
None
:
cmd
+=
[
wutils
.
LOAD
]
if
output
is
None
:
else
:
cmd
+=
[
output
]
output
=
wutils
.
LOAD
cmd
+=
[
output
]
result
=
self
.
__run
(
*
cmd
)
result
=
self
.
__run
(
*
cmd
)
# if output is LOADed, there
# if output is LOADed, there
# will only be one entry in
# will only be one entry in
# the result dict.
# the result dict.
if
output
is
None
:
return
list
(
result
.
values
())[
0
]
if
output
==
wutils
.
LOAD
:
return
list
(
result
.
values
())[
0
]
else
:
return
result
else
:
return
result
@wutils.fileOrImage
()
@wutils.fileOrImage
()
@wutils.fslwrapper
@wutils.fslwrapper
...
...
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