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
51123396
Commit
51123396
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Fixed up fslmaths module
parent
b118c2d0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/wrappers/fslmaths.py
+56
-54
56 additions, 54 deletions
fsl/wrappers/fslmaths.py
with
56 additions
and
54 deletions
fsl/wrappers/fslmaths.py
+
56
−
54
View file @
51123396
...
...
@@ -9,7 +9,8 @@ for the ``fslmaths`` command-line tool.
"""
import
fsl.utils.run
as
run
import
fsl.utils.run
as
run
from
.
import
wrapperutils
as
wutils
class
fslmaths
(
object
):
...
...
@@ -17,142 +18,143 @@ class fslmaths(object):
def
__init__
(
self
,
input
):
"""
Constructor.
"""
self
.
inputImage
=
input
self
.
outputImage
=
None
self
.
operations
=
[]
self
.
__input
=
input
self
.
__args
=
[]
def
abs
(
self
):
"""
Absolute value.
"""
self
.
operation
s
.
append
(
"
-abs
"
)
self
.
__arg
s
.
append
(
"
-abs
"
)
return
self
def
bin
(
self
):
"""
Use (current image>0) to binarise.
"""
self
.
operation
s
.
append
(
"
-bin
"
)
self
.
__arg
s
.
append
(
"
-bin
"
)
return
self
def
binv
(
self
):
"""
Binarise and invert (binarisation and logical inversion).
"""
self
.
operation
s
.
append
(
"
-binv
"
)
self
.
__arg
s
.
append
(
"
-binv
"
)
return
self
def
recip
(
self
):
"""
Reciprocal (1/current image).
"""
self
.
operation
s
.
append
(
"
-recip
"
)
self
.
__arg
s
.
append
(
"
-recip
"
)
return
self
def
Tmean
(
self
):
"""
Mean across time.
"""
self
.
operation
s
.
append
(
"
-Tmean
"
)
self
.
__arg
s
.
append
(
"
-Tmean
"
)
return
self
def
Tstd
(
self
):
"""
Standard deviation across time.
"""
self
.
operation
s
.
append
(
"
-Tstd
"
)
self
.
__arg
s
.
append
(
"
-Tstd
"
)
return
self
def
Tmin
(
self
):
"""
Min across time.
"""
self
.
operation
s
.
append
(
"
-Tmin
"
)
self
.
__arg
s
.
append
(
"
-Tmin
"
)
return
self
def
Tmax
(
self
):
"""
Max across time.
"""
self
.
operation
s
.
append
(
"
-Tmax
"
)
self
.
__arg
s
.
append
(
"
-Tmax
"
)
return
self
def
fillh
(
self
):
"""
fill holes in a binary mask (holes are internal - i.e. do not touch
the edge of the FOV).
"""
self
.
operation
s
.
append
(
"
-fillh
"
)
self
.
__arg
s
.
append
(
"
-fillh
"
)
return
self
def
ero
(
self
,
repeat
=
1
):
"""
Erode by zeroing non-zero voxels when zero voxels in kernel.
"""
for
i
in
range
(
repeat
):
self
.
operation
s
.
append
(
"
-ero
"
)
self
.
__arg
s
.
append
(
"
-ero
"
)
return
self
def
dilM
(
self
,
repeat
=
1
):
"""
Mean Dilation of non-zero voxels.
"""
for
i
in
range
(
repeat
):
self
.
operation
s
.
append
(
"
-dilM
"
)
self
.
__arg
s
.
append
(
"
-dilM
"
)
return
self
def
dilF
(
self
,
repeat
=
1
):
"""
Maximum filtering of all voxels.
"""
for
i
in
range
(
repeat
):
self
.
operation
s
.
append
(
"
-dilF
"
)
self
.
__arg
s
.
append
(
"
-dilF
"
)
return
self
def
add
(
self
,
i
nput
):
def
add
(
self
,
i
mage
):
"""
Add input to current image.
"""
self
.
operations
.
app
end
(
"
-add
{0}
"
.
format
(
input
))
self
.
__args
.
ext
end
(
(
"
-add
"
,
image
))
return
self
def
sub
(
self
,
i
nput
):
"""
Subtract i
nput
from current image.
"""
self
.
operations
.
app
end
(
"
-sub
{0}
"
.
format
(
input
))
def
sub
(
self
,
i
mage
):
"""
Subtract i
mage
from current image.
"""
self
.
__args
.
ext
end
(
(
"
-sub
"
,
image
))
return
self
def
mul
(
self
,
i
nput
):
"""
Multiply current image by i
nput
.
"""
self
.
operations
.
app
end
(
"
-mul
{0}
"
.
format
(
input
))
def
mul
(
self
,
i
mage
):
"""
Multiply current image by i
mage
.
"""
self
.
__args
.
ext
end
(
(
"
-mul
"
,
image
))
return
self
def
div
(
self
,
i
nput
):
"""
Divide current image by i
nput
.
"""
self
.
operations
.
app
end
(
"
-div
{0}
"
.
format
(
input
))
def
div
(
self
,
i
mage
):
"""
Divide current image by i
mage
.
"""
self
.
__args
.
ext
end
(
(
"
-div
"
,
image
))
return
self
def
mas
(
self
,
image
):
"""
Use image (>0) to mask current image.
"""
self
.
operations
.
app
end
(
"
-mas
{0}
"
.
format
(
image
))
self
.
__args
.
ext
end
(
(
"
-mas
"
,
image
))
return
self
def
rem
(
self
,
i
nput
):
"""
Divide current image by following i
nput
and take remainder.
"""
self
.
operations
.
app
end
(
"
-rem
{0}
"
.
format
(
input
))
def
rem
(
self
,
i
mage
):
"""
Divide current image by following i
mage
and take remainder.
"""
self
.
__args
.
ext
end
(
(
"
-rem
"
,
image
))
return
self
def
thr
(
self
,
i
nput
):
"""
use i
nput
number to threshold current image (zero < i
nput
).
"""
self
.
operations
.
app
end
(
"
-thr
{0}
"
.
format
(
input
))
def
thr
(
self
,
i
mage
):
"""
use i
mage
number to threshold current image (zero < i
mage
).
"""
self
.
__args
.
ext
end
(
(
"
-thr
"
,
image
))
return
self
def
uthr
(
self
,
i
nput
):
"""
use i
nput
number to upper-threshold current image (zero
def
uthr
(
self
,
i
mage
):
"""
use i
mage
number to upper-threshold current image (zero
anything above the number).
"""
self
.
operations
.
app
end
(
"
-uthr
{0}
"
.
format
(
input
))
self
.
__args
.
ext
end
(
(
"
-uthr
"
,
image
))
return
self
def
inm
(
self
,
i
nput
):
def
inm
(
self
,
i
mage
):
"""
Intensity normalisation (per 3D volume mean)
"""
self
.
operations
.
app
end
(
"
-inm
{0}
"
.
format
(
input
))
self
.
__args
.
ext
end
(
(
"
-inm
"
,
image
))
return
self
def
bptf
(
self
,
hp_sigma
,
lp_sigma
):
"""
Bandpass temporal filtering; nonlinear highpass and Gaussian linear
lowpass (with sigmas in volumes, not seconds); set either sigma<0 to
skip that filter.
"""
self
.
operations
.
app
end
(
"
-bptf
{0} {1}
"
.
format
(
hp_sigma
,
lp_sigma
))
self
.
__args
.
ext
end
(
(
"
-bptf
"
,
hp_sigma
,
lp_sigma
))
return
self
def
toString
(
self
):
"""
Generate fslmaths command string.
"""
cmd
=
"
fslmaths {0}
"
.
format
(
self
.
inputImage
)
for
oper
in
self
.
operations
:
cmd
=
cmd
+
oper
+
"
"
cmd
=
cmd
+
self
.
outputImage
return
cmd
def
run
(
self
,
output
=
None
):
"""
Save output of operations to image.
"""
if
output
:
self
.
outputImage
=
output
else
:
self
.
outputImage
=
self
.
inputImage
run
.
runfsl
(
self
.
toString
())
cmd
=
[
'
fslmaths
'
,
self
.
__input
]
+
self
.
__args
if
output
is
None
:
cmd
+=
[
wutils
.
LOAD
]
else
:
cmd
+=
[
output
]
result
=
self
.
__run
(
*
cmd
)
# if output is LOADed, there
# will only be one entry in
# the result dict.
if
output
is
None
:
return
list
(
result
.
values
())[
0
]
else
:
return
output
return
self
.
outputImage
@wutils.fileOrImage
()
def
__run
(
self
,
*
cmd
):
"""
Run the given ``fslmaths`` command.
"""
return
run
.
runfsl
([
str
(
c
)
for
c
in
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