Skip to content

Commit d323b92

Browse files
committed
Merge pull request #512 from nicholsn/enh/MathsMaxImage
Enh/maths max image
2 parents 800c535 + ee3c5dc commit d323b92

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

nipype/interfaces/fsl/maths.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,28 @@ class MeanImage(MathsCommand):
117117
input_spec = MeanImageInput
118118
_suffix = "_mean"
119119

120+
class MaxImageInput(MathsInput):
121+
122+
dimension = traits.Enum("T", "X", "Y", "Z", usedefault=True, argstr="-%smax", position=4,
123+
desc="dimension to max across")
124+
125+
126+
class MaxImage(MathsCommand):
127+
"""Use fslmaths to generate a max image across a given dimension.
128+
129+
Examples
130+
--------
131+
from nipype.interfaces.fsl.maths import MaxImage
132+
maxer = MaxImage()
133+
maxer.inputs.in_file = "functional.nii"
134+
maxer.dimension = "T"
135+
maths.cmdline
136+
fslmaths functional.nii -Tmax functional_max.nii
137+
138+
"""
139+
input_spec = MaxImageInput
140+
_suffix = "_max"
141+
120142

121143
class IsotropicSmoothInput(MathsInput):
122144

nipype/interfaces/fsl/tests/test_maths.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,32 @@ def test_meanimage():
169169
# Clean up our mess
170170
clean_directory(testdir, origdir, ftype)
171171

172+
@skipif(no_fsl)
173+
def test_maximage():
174+
files, testdir, origdir, ftype = create_files_in_directory()
175+
176+
# Get the command
177+
maxer = fsl.MaxImage(in_file="a.nii",out_file="b.nii")
178+
179+
# Test the underlying command
180+
yield assert_equal, maxer.cmd, "fslmaths"
181+
182+
# Test the defualt opstring
183+
yield assert_equal, maxer.cmdline, "fslmaths a.nii -Tmax b.nii"
184+
185+
# Test the other dimensions
186+
cmdline = "fslmaths a.nii -%smax b.nii"
187+
for dim in ["X","Y","Z","T"]:
188+
maxer.inputs.dimension=dim
189+
yield assert_equal, maxer.cmdline, cmdline%dim
190+
191+
# Test the auto naming
192+
maxer = fsl.MaxImage(in_file="a.nii")
193+
yield assert_equal, maxer.cmdline, "fslmaths a.nii -Tmax %s"%os.path.join(testdir, "a_max.nii")
194+
195+
# Clean up our mess
196+
clean_directory(testdir, origdir, ftype)
197+
172198
@skipif(no_fsl)
173199
def test_smooth():
174200
files, testdir, origdir, ftype = create_files_in_directory()

0 commit comments

Comments
 (0)