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
No related tags found
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.
...
@@ -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
):
class
fslmaths
(
object
):
...
@@ -17,142 +18,143 @@ class fslmaths(object):
...
@@ -17,142 +18,143 @@ class fslmaths(object):
def
__init__
(
self
,
input
):
def
__init__
(
self
,
input
):
"""
Constructor.
"""
"""
Constructor.
"""
self
.
inputImage
=
input
self
.
__input
=
input
self
.
outputImage
=
None
self
.
__args
=
[]
self
.
operations
=
[]
def
abs
(
self
):
def
abs
(
self
):
"""
Absolute value.
"""
"""
Absolute value.
"""
self
.
operation
s
.
append
(
"
-abs
"
)
self
.
__arg
s
.
append
(
"
-abs
"
)
return
self
return
self
def
bin
(
self
):
def
bin
(
self
):
"""
Use (current image>0) to binarise.
"""
"""
Use (current image>0) to binarise.
"""
self
.
operation
s
.
append
(
"
-bin
"
)
self
.
__arg
s
.
append
(
"
-bin
"
)
return
self
return
self
def
binv
(
self
):
def
binv
(
self
):
"""
Binarise and invert (binarisation and logical inversion).
"""
"""
Binarise and invert (binarisation and logical inversion).
"""
self
.
operation
s
.
append
(
"
-binv
"
)
self
.
__arg
s
.
append
(
"
-binv
"
)
return
self
return
self
def
recip
(
self
):
def
recip
(
self
):
"""
Reciprocal (1/current image).
"""
"""
Reciprocal (1/current image).
"""
self
.
operation
s
.
append
(
"
-recip
"
)
self
.
__arg
s
.
append
(
"
-recip
"
)
return
self
return
self
def
Tmean
(
self
):
def
Tmean
(
self
):
"""
Mean across time.
"""
"""
Mean across time.
"""
self
.
operation
s
.
append
(
"
-Tmean
"
)
self
.
__arg
s
.
append
(
"
-Tmean
"
)
return
self
return
self
def
Tstd
(
self
):
def
Tstd
(
self
):
"""
Standard deviation across time.
"""
"""
Standard deviation across time.
"""
self
.
operation
s
.
append
(
"
-Tstd
"
)
self
.
__arg
s
.
append
(
"
-Tstd
"
)
return
self
return
self
def
Tmin
(
self
):
def
Tmin
(
self
):
"""
Min across time.
"""
"""
Min across time.
"""
self
.
operation
s
.
append
(
"
-Tmin
"
)
self
.
__arg
s
.
append
(
"
-Tmin
"
)
return
self
return
self
def
Tmax
(
self
):
def
Tmax
(
self
):
"""
Max across time.
"""
"""
Max across time.
"""
self
.
operation
s
.
append
(
"
-Tmax
"
)
self
.
__arg
s
.
append
(
"
-Tmax
"
)
return
self
return
self
def
fillh
(
self
):
def
fillh
(
self
):
"""
fill holes in a binary mask (holes are internal - i.e. do not touch
"""
fill holes in a binary mask (holes are internal - i.e. do not touch
the edge of the FOV).
"""
the edge of the FOV).
"""
self
.
operation
s
.
append
(
"
-fillh
"
)
self
.
__arg
s
.
append
(
"
-fillh
"
)
return
self
return
self
def
ero
(
self
,
repeat
=
1
):
def
ero
(
self
,
repeat
=
1
):
"""
Erode by zeroing non-zero voxels when zero voxels in kernel.
"""
"""
Erode by zeroing non-zero voxels when zero voxels in kernel.
"""
for
i
in
range
(
repeat
):
for
i
in
range
(
repeat
):
self
.
operation
s
.
append
(
"
-ero
"
)
self
.
__arg
s
.
append
(
"
-ero
"
)
return
self
return
self
def
dilM
(
self
,
repeat
=
1
):
def
dilM
(
self
,
repeat
=
1
):
"""
Mean Dilation of non-zero voxels.
"""
"""
Mean Dilation of non-zero voxels.
"""
for
i
in
range
(
repeat
):
for
i
in
range
(
repeat
):
self
.
operation
s
.
append
(
"
-dilM
"
)
self
.
__arg
s
.
append
(
"
-dilM
"
)
return
self
return
self
def
dilF
(
self
,
repeat
=
1
):
def
dilF
(
self
,
repeat
=
1
):
"""
Maximum filtering of all voxels.
"""
"""
Maximum filtering of all voxels.
"""
for
i
in
range
(
repeat
):
for
i
in
range
(
repeat
):
self
.
operation
s
.
append
(
"
-dilF
"
)
self
.
__arg
s
.
append
(
"
-dilF
"
)
return
self
return
self
def
add
(
self
,
i
nput
):
def
add
(
self
,
i
mage
):
"""
Add input to current image.
"""
"""
Add input to current image.
"""
self
.
operations
.
app
end
(
"
-add
{0}
"
.
format
(
input
))
self
.
__args
.
ext
end
(
(
"
-add
"
,
image
))
return
self
return
self
def
sub
(
self
,
i
nput
):
def
sub
(
self
,
i
mage
):
"""
Subtract i
nput
from current image.
"""
"""
Subtract i
mage
from current image.
"""
self
.
operations
.
app
end
(
"
-sub
{0}
"
.
format
(
input
))
self
.
__args
.
ext
end
(
(
"
-sub
"
,
image
))
return
self
return
self
def
mul
(
self
,
i
nput
):
def
mul
(
self
,
i
mage
):
"""
Multiply current image by i
nput
.
"""
"""
Multiply current image by i
mage
.
"""
self
.
operations
.
app
end
(
"
-mul
{0}
"
.
format
(
input
))
self
.
__args
.
ext
end
(
(
"
-mul
"
,
image
))
return
self
return
self
def
div
(
self
,
i
nput
):
def
div
(
self
,
i
mage
):
"""
Divide current image by i
nput
.
"""
"""
Divide current image by i
mage
.
"""
self
.
operations
.
app
end
(
"
-div
{0}
"
.
format
(
input
))
self
.
__args
.
ext
end
(
(
"
-div
"
,
image
))
return
self
return
self
def
mas
(
self
,
image
):
def
mas
(
self
,
image
):
"""
Use image (>0) to mask current image.
"""
"""
Use image (>0) to mask current image.
"""
self
.
operations
.
app
end
(
"
-mas
{0}
"
.
format
(
image
))
self
.
__args
.
ext
end
(
(
"
-mas
"
,
image
))
return
self
return
self
def
rem
(
self
,
i
nput
):
def
rem
(
self
,
i
mage
):
"""
Divide current image by following i
nput
and take remainder.
"""
"""
Divide current image by following i
mage
and take remainder.
"""
self
.
operations
.
app
end
(
"
-rem
{0}
"
.
format
(
input
))
self
.
__args
.
ext
end
(
(
"
-rem
"
,
image
))
return
self
return
self
def
thr
(
self
,
i
nput
):
def
thr
(
self
,
i
mage
):
"""
use i
nput
number to threshold current image (zero < i
nput
).
"""
"""
use i
mage
number to threshold current image (zero < i
mage
).
"""
self
.
operations
.
app
end
(
"
-thr
{0}
"
.
format
(
input
))
self
.
__args
.
ext
end
(
(
"
-thr
"
,
image
))
return
self
return
self
def
uthr
(
self
,
i
nput
):
def
uthr
(
self
,
i
mage
):
"""
use i
nput
number to upper-threshold current image (zero
"""
use i
mage
number to upper-threshold current image (zero
anything above the number).
"""
anything above the number).
"""
self
.
operations
.
app
end
(
"
-uthr
{0}
"
.
format
(
input
))
self
.
__args
.
ext
end
(
(
"
-uthr
"
,
image
))
return
self
return
self
def
inm
(
self
,
i
nput
):
def
inm
(
self
,
i
mage
):
"""
Intensity normalisation (per 3D volume mean)
"""
"""
Intensity normalisation (per 3D volume mean)
"""
self
.
operations
.
app
end
(
"
-inm
{0}
"
.
format
(
input
))
self
.
__args
.
ext
end
(
(
"
-inm
"
,
image
))
return
self
return
self
def
bptf
(
self
,
hp_sigma
,
lp_sigma
):
def
bptf
(
self
,
hp_sigma
,
lp_sigma
):
"""
Bandpass temporal filtering; nonlinear highpass and Gaussian linear
"""
Bandpass temporal filtering; nonlinear highpass and Gaussian linear
lowpass (with sigmas in volumes, not seconds); set either sigma<0 to
lowpass (with sigmas in volumes, not seconds); set either sigma<0 to
skip that filter.
"""
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
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
):
def
run
(
self
,
output
=
None
):
"""
Save output of operations to image.
"""
"""
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