@@ -139,13 +139,41 @@ class UnaryMaths(MathsCommand):
139
139
140
140
Examples
141
141
--------
142
+ >>> import copy
142
143
>>> from nipype.interfaces import niftyseg
143
- >>> node = niftyseg.UnaryMaths()
144
- >>> node.inputs.in_file = 'im1.nii'
145
- >>> node.inputs.operation = 'sqrt'
146
- >>> node.inputs.output_datatype = 'float'
147
- >>> node.cmdline # doctest: +ALLOW_UNICODE
144
+ >>> unary = niftyseg.UnaryMaths()
145
+ >>> unary.inputs.output_datatype = 'float'
146
+ >>> unary.inputs.in_file = 'im1.nii'
147
+ >>> # Test sqrt operation
148
+ >>> unary_sqrt = copy.deepcopy(unary)
149
+ >>> unary_sqrt.inputs.operation = 'sqrt'
150
+ >>> unary_sqrt.cmdline # doctest: +ALLOW_UNICODE
148
151
'seg_maths im1.nii -sqrt -odt float im1_sqrt.nii'
152
+ >>> unary_sqrt.run() # doctest: +SKIP
153
+ >>> # Test sqrt operation
154
+ >>> unary_abs = copy.deepcopy(unary)
155
+ >>> unary_abs.inputs.operation = 'abs'
156
+ >>> unary_abs.cmdline # doctest: +ALLOW_UNICODE
157
+ 'seg_maths im1.nii -abs -odt float im1_abs.nii'
158
+ >>> unary_abs.run() # doctest: +SKIP
159
+ >>> # Test bin operation
160
+ >>> unary_bin = copy.deepcopy(unary)
161
+ >>> unary_bin.inputs.operation = 'bin'
162
+ >>> unary_bin.cmdline # doctest: +ALLOW_UNICODE
163
+ 'seg_maths im1.nii -bin -odt float im1_bin.nii'
164
+ >>> unary_bin.run() # doctest: +SKIP
165
+ >>> # Test otsu operation
166
+ >>> unary_otsu = copy.deepcopy(unary)
167
+ >>> unary_otsu.inputs.operation = 'otsu'
168
+ >>> unary_otsu.cmdline # doctest: +ALLOW_UNICODE
169
+ 'seg_maths im1.nii -otsu -odt float im1_otsu.nii'
170
+ >>> unary_otsu.run() # doctest: +SKIP
171
+ >>> # Test isnan operation
172
+ >>> unary_isnan = copy.deepcopy(unary)
173
+ >>> unary_isnan.inputs.operation = 'isnan'
174
+ >>> unary_isnan.cmdline # doctest: +ALLOW_UNICODE
175
+ 'seg_maths im1.nii -isnan -odt float im1_isnan.nii'
176
+ >>> unary_isnan.run() # doctest: +SKIP
149
177
150
178
"""
151
179
input_spec = UnaryMathsInput
@@ -226,28 +254,71 @@ class BinaryMaths(MathsCommand):
226
254
227
255
Examples
228
256
--------
257
+ >>> import copy
229
258
>>> from nipype.interfaces import niftyseg
230
- >>> node = niftyseg.BinaryMaths()
231
- >>> node.inputs.in_file = 'im1.nii'
232
- >>> node.inputs.operation = 'sub'
233
- >>> node.inputs.operand_file = 'im2.nii'
234
- >>> node.inputs.output_datatype = 'float'
235
- >>> node.cmdline # doctest: +ALLOW_UNICODE
259
+ >>> binary = niftyseg.BinaryMaths()
260
+ >>> binary.inputs.in_file = 'im1.nii'
261
+ >>> binary.inputs.output_datatype = 'float'
262
+ >>> # Test sub operation
263
+ >>> binary_sub = copy.deepcopy(binary)
264
+ >>> binary_sub.inputs.operation = 'sub'
265
+ >>> binary_sub.inputs.operand_file = 'im2.nii'
266
+ >>> binary_sub.cmdline # doctest: +ALLOW_UNICODE
236
267
'seg_maths im1.nii -sub im2.nii -odt float im1_sub.nii'
268
+ >>> binary_sub.run() # doctest: +SKIP
269
+ >>> # Test mul operation
270
+ >>> binary_mul = copy.deepcopy(binary)
271
+ >>> binary_mul.inputs.operation = 'mul'
272
+ >>> binary_mul.inputs.operand_value = 2.0
273
+ >>> binary_mul.cmdline # doctest: +ALLOW_UNICODE
274
+ 'seg_maths im1.nii -mul 2.0 -odt float im1_mul.nii'
275
+ >>> binary_mul.run() # doctest: +SKIP
276
+ >>> # Test llsnorm operation
277
+ >>> binary_llsnorm = copy.deepcopy(binary)
278
+ >>> binary_llsnorm.inputs.operation = 'llsnorm'
279
+ >>> binary_llsnorm.inputs.operand_file = 'im2.nii'
280
+ >>> binary_llsnorm.cmdline # doctest: +ALLOW_UNICODE
281
+ 'seg_maths im1.nii -llsnorm im2.nii -odt float im1_llsnorm.nii'
282
+ >>> binary_llsnorm.run() # doctest: +SKIP
283
+ >>> # Test splitinter operation
284
+ >>> binary_splitinter = copy.deepcopy(binary)
285
+ >>> binary_splitinter.inputs.operation = 'llsnorm'
286
+ >>> binary_splitinter.inputs.operand_str = 'z'
287
+ >>> binary_splitinter.cmdline # doctest: +ALLOW_UNICODE
288
+ 'seg_maths im1.nii -splitinter z -odt float im1_splitinter.nii'
289
+ >>> binary_splitinter.run() # doctest: +SKIP
237
290
238
291
"""
239
292
input_spec = BinaryMathsInput
240
293
241
294
def _format_arg (self , opt , spec , val ):
242
295
"""Convert input to appropriate format for seg_maths."""
243
- if opt == 'operand_value' and float (val ) == 0.0 :
244
- return '0'
245
-
246
296
if opt == 'operand_str' and self .inputs .operation != 'splitinter' :
247
297
err = 'operand_str set but with an operation different than \
248
298
"splitinter"'
249
299
raise NipypeInterfaceError (err )
250
300
301
+ if opt == 'operation' :
302
+ # Only float
303
+ if val in ['pow' , 'thr' , 'uthr' , 'smo' , 'edge' , 'sobel3' , 'sobel5' ,
304
+ 'smol' ]:
305
+ if not isdefined (self .inputs .operand_value ):
306
+ err = 'operand_value not set for {0}.' .format (val )
307
+ raise NipypeInterfaceError (err )
308
+ # only files
309
+ elif val in ['min' , 'llsnorm' , 'masknan' , 'hdr_copy' ]:
310
+ if not isdefined (self .inputs .operand_file ):
311
+ err = 'operand_file not set for {0}.' .format (val )
312
+ raise NipypeInterfaceError (err )
313
+ # splitinter:
314
+ elif val == 'splitinter' :
315
+ if not isdefined (self .inputs .operand_str ):
316
+ err = 'operand_str not set for splitinter.'
317
+ raise NipypeInterfaceError (err )
318
+
319
+ if opt == 'operand_value' and float (val ) == 0.0 :
320
+ return '0'
321
+
251
322
return super (BinaryMaths , self )._format_arg (opt , spec , val )
252
323
253
324
def _overload_extension (self , value , name = None ):
@@ -293,22 +364,40 @@ class BinaryMathsInteger(MathsCommand):
293
364
294
365
Examples
295
366
--------
367
+ >>> import copy
296
368
>>> from nipype.interfaces.niftyseg import BinaryMathsInteger
297
- >>> node = BinaryMathsInteger()
298
- >>> node.inputs.in_file = 'im1.nii'
299
- >>> node.inputs.operation = 'dil'
300
- >>> node.inputs.operand_value = 2
301
- >>> node.inputs.output_datatype = 'float'
302
- >>> node.cmdline # doctest: +ALLOW_UNICODE
369
+ >>> binaryi = BinaryMathsInteger()
370
+ >>> binaryi.inputs.in_file = 'im1.nii'
371
+ >>> binaryi.inputs.output_datatype = 'float'
372
+ >>> # Test dil operation
373
+ >>> binaryi_dil = copy.deepcopy(binaryi)
374
+ >>> binaryi_dil.inputs.operation = 'dil'
375
+ >>> binaryi_dil.inputs.operand_value = 2
376
+ >>> binaryi_dil.cmdline # doctest: +ALLOW_UNICODE
303
377
'seg_maths im1.nii -dil 2 -odt float im1_dil.nii'
378
+ >>> binaryi_dil.run() # doctest: +SKIP
379
+ >>> # Test dil operation
380
+ >>> binaryi_ero = copy.deepcopy(binaryi)
381
+ >>> binaryi_ero.inputs.operation = 'ero'
382
+ >>> binaryi_ero.inputs.operand_value = 1
383
+ >>> binaryi_ero.cmdline # doctest: +ALLOW_UNICODE
384
+ 'seg_maths im1.nii -ero 1 -odt float im1_ero.nii'
385
+ >>> binaryi_ero.run() # doctest: +SKIP
386
+ >>> # Test pad operation
387
+ >>> binaryi_pad = copy.deepcopy(binaryi)
388
+ >>> binaryi_pad.inputs.operation = 'pad'
389
+ >>> binaryi_pad.inputs.operand_value = 4
390
+ >>> binaryi_pad.cmdline # doctest: +ALLOW_UNICODE
391
+ 'seg_maths im1.nii -pad 4 -odt float im1_pad.nii'
392
+ >>> binaryi_pad.run() # doctest: +SKIP
304
393
305
394
"""
306
395
input_spec = BinaryMathsInputInteger
307
396
308
397
309
398
class TupleMathsInput (MathsInput ):
310
399
"""Input Spec for seg_maths Tuple operations."""
311
- operation = traits .Enum ('lncc' , 'lssd' , 'lltsnorm' , 'qlsnorm' ,
400
+ operation = traits .Enum ('lncc' , 'lssd' , 'lltsnorm' ,
312
401
mandatory = True ,
313
402
argstr = '-%s' ,
314
403
position = 4 ,
@@ -354,25 +443,45 @@ class TupleMaths(MathsCommand):
354
443
on a kernel with <std>
355
444
-lltsnorm <file_norm> <float> Linear LTS normalisation assuming
356
445
<float> percent outliers
357
- -qlsnorm <order> <file_norm> LS normalisation of <order>
358
- between current and <file_norm>
359
446
360
447
For source code, see http://cmictig.cs.ucl.ac.uk/wiki/index.php/NiftySeg
361
448
For Documentation, see:
362
449
http://cmictig.cs.ucl.ac.uk/wiki/index.php/NiftySeg_documentation
363
450
364
451
Examples
365
452
--------
453
+ >>> import copy
366
454
>>> from nipype.interfaces import niftyseg
367
- >>> node = niftyseg.TupleMaths()
368
- >>> node.inputs.in_file = 'im1.nii'
369
- >>> node.inputs.operation = 'lncc'
370
- >>> node.inputs.operand_file1 = 'im2.nii'
371
- >>> node.inputs.operand_value2 = 2.0
372
- >>> node.inputs.output_datatype = 'float'
373
- >>> node.cmdline # doctest: +ALLOW_UNICODE
455
+ >>> tuple = niftyseg.TupleMaths()
456
+ >>> tuple.inputs.in_file = 'im1.nii'
457
+ >>> tuple.inputs.output_datatype = 'float'
458
+
459
+ >>> # Test lncc operation
460
+ >>> tuple_lncc = copy.deepcopy(binary)
461
+ >>> tuple_lncc.inputs.operation = 'lncc'
462
+ >>> tuple_lncc.inputs.operand_file1 = 'im2.nii'
463
+ >>> tuple_lncc.inputs.operand_value2 = 2.0
464
+ >>> tuple_lncc.cmdline # doctest: +ALLOW_UNICODE
374
465
'seg_maths im1.nii -lncc im2.nii 2.00000000 -odt float im1_lncc.nii'
375
-
466
+ >>> tuple_lncc.run() # doctest: +SKIP
467
+
468
+ >>> # Test lssd operation
469
+ >>> tuple_lssd = copy.deepcopy(binary)
470
+ >>> tuple_lssd.inputs.operation = 'lssd'
471
+ >>> tuple_lssd.inputs.operand_file1 = 'im2.nii'
472
+ >>> tuple_lssd.inputs.operand_value2 = 1.0
473
+ >>> tuple_lssd.cmdline # doctest: +ALLOW_UNICODE
474
+ 'seg_maths im1.nii -lssd im2.nii 1.00000000 -odt float im1_lssd.nii'
475
+ >>> tuple_lssd.run() # doctest: +SKIP
476
+
477
+ >>> # Test lltsnorm operation
478
+ >>> tuple_lltsnorm = copy.deepcopy(binary)
479
+ >>> tuple_lltsnorm.inputs.operation = 'lltsnorm'
480
+ >>> tuple_lltsnorm.inputs.operand_file1 = 'im2.nii'
481
+ >>> tuple_lltsnorm.inputs.operand_value2 = 0.01
482
+ >>> tuple_lltsnorm.cmdline # doctest: +ALLOW_UNICODE
483
+ 'seg_maths im1.nii -lltsnorm im2.nii 0.01 -odt float im1_lltsnorm.nii'
484
+ >>> tuple_lltsnorm.run() # doctest: +SKIP
376
485
"""
377
486
input_spec = TupleMathsInput
378
487
0 commit comments