Skip to content

Commit 62e4958

Browse files
authored
Merge pull request #2087 from tsalo/master
[ENH] Add AFNI 3dedge3
2 parents 9ac1058 + a0a506e commit 62e4958

File tree

3 files changed

+151
-1
lines changed

3 files changed

+151
-1
lines changed

nipype/interfaces/afni/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
Seg, SkullStrip, TCorr1D, TCorrMap, TCorrelate,
1818
TShift, Volreg, Warp, QwarpPlusMinus)
1919
from .svm import (SVMTest, SVMTrain)
20-
from .utils import (AFNItoNIFTI, Autobox, BrickStat, Calc, Copy,
20+
from .utils import (AFNItoNIFTI, Autobox, BrickStat, Calc, Copy, Edge3,
2121
Eval, FWHMx,
2222
MaskTool, Merge, Notes, Refit, Resample, TCat, TStat, To3D,
2323
Unifize, ZCutUp, GCOR,)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..utils import Edge3
4+
5+
6+
def test_Edge3_inputs():
7+
input_map = dict(args=dict(argstr='%s',
8+
),
9+
datum=dict(argstr='-datum %s',
10+
),
11+
environ=dict(nohash=True,
12+
usedefault=True,
13+
),
14+
fscale=dict(argstr='-fscale',
15+
xor=['gscale', 'nscale', 'scale_floats'],
16+
),
17+
gscale=dict(argstr='-gscale',
18+
xor=['fscale', 'nscale', 'scale_floats'],
19+
),
20+
ignore_exception=dict(nohash=True,
21+
usedefault=True,
22+
),
23+
in_file=dict(argstr='-input %s',
24+
copyfile=False,
25+
mandatory=True,
26+
position=0,
27+
),
28+
nscale=dict(argstr='-nscale',
29+
xor=['fscale', 'gscale', 'scale_floats'],
30+
),
31+
out_file=dict(argstr='-prefix %s',
32+
position=-1,
33+
),
34+
outputtype=dict(),
35+
scale_floats=dict(argstr='-scale_floats %f',
36+
xor=['fscale', 'gscale', 'nscale'],
37+
),
38+
terminal_output=dict(nohash=True,
39+
),
40+
verbose=dict(argstr='-verbose',
41+
),
42+
)
43+
inputs = Edge3.input_spec()
44+
45+
for key, metadata in list(input_map.items()):
46+
for metakey, value in list(metadata.items()):
47+
assert getattr(inputs.traits()[key], metakey) == value
48+
49+
50+
def test_Edge3_outputs():
51+
output_map = dict(out_file=dict(),
52+
)
53+
outputs = Edge3.output_spec()
54+
55+
for key, metadata in list(output_map.items()):
56+
for metakey, value in list(metadata.items()):
57+
assert getattr(outputs.traits()[key], metakey) == value

nipype/interfaces/afni/utils.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,99 @@ class Copy(AFNICommand):
394394
output_spec = AFNICommandOutputSpec
395395

396396

397+
class Edge3InputSpec(AFNICommandInputSpec):
398+
in_file = File(
399+
desc='input file to 3dedge3',
400+
argstr='-input %s',
401+
position=0,
402+
mandatory=True,
403+
exists=True,
404+
copyfile=False)
405+
out_file = File(
406+
desc='output image file name',
407+
position=-1,
408+
argstr='-prefix %s')
409+
datum = traits.Enum(
410+
'byte','short','float',
411+
argstr='-datum %s',
412+
desc='specify data type for output. Valid types are \'byte\', '
413+
'\'short\' and \'float\'.')
414+
fscale = traits.Bool(
415+
desc='Force scaling of the output to the maximum integer range.',
416+
argstr='-fscale',
417+
xor=['gscale', 'nscale', 'scale_floats'])
418+
gscale = traits.Bool(
419+
desc='Same as \'-fscale\', but also forces each output sub-brick to '
420+
'to get the same scaling factor.',
421+
argstr='-gscale',
422+
xor=['fscale', 'nscale', 'scale_floats'])
423+
nscale = traits.Bool(
424+
desc='Don\'t do any scaling on output to byte or short datasets.',
425+
argstr='-nscale',
426+
xor=['fscale', 'gscale', 'scale_floats'])
427+
scale_floats = traits.Float(
428+
desc='Multiply input by VAL, but only if the input datum is '
429+
'float. This is needed when the input dataset '
430+
'has a small range, like 0 to 2.0 for instance. '
431+
'With such a range, very few edges are detected due to '
432+
'what I suspect to be truncation problems. '
433+
'Multiplying such a dataset by 10000 fixes the problem '
434+
'and the scaling is undone at the output.',
435+
argstr='-scale_floats %f',
436+
xor=['fscale', 'gscale', 'nscale'])
437+
verbose = traits.Bool(
438+
desc='Print out some information along the way.',
439+
argstr='-verbose')
440+
441+
442+
class Edge3(AFNICommand):
443+
"""Does 3D Edge detection using the library 3DEdge
444+
by Gregoire Malandain ([email protected]).
445+
446+
For complete details, see the `3dedge3 Documentation.
447+
<https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dedge3.html>`_
448+
449+
references_ = [{'entry': BibTeX('@article{Deriche1987,'
450+
'author={R. Deriche},'
451+
'title={Optimal edge detection using recursive filtering},'
452+
'journal={International Journal of Computer Vision},'
453+
'volume={2},',
454+
'pages={167-187},'
455+
'year={1987},'
456+
'}'),
457+
'tags': ['method'],
458+
},
459+
{'entry': BibTeX('@article{MongaDericheMalandainCocquerez1991,'
460+
'author={O. Monga, R. Deriche, G. Malandain, J.P. Cocquerez},'
461+
'title={Recursive filtering and edge tracking: two primary tools for 3D edge detection},'
462+
'journal={Image and vision computing},'
463+
'volume={9},',
464+
'pages={203-214},'
465+
'year={1991},'
466+
'}'),
467+
'tags': ['method'],
468+
},
469+
]
470+
471+
Examples
472+
========
473+
474+
>>> from nipype.interfaces import afni
475+
>>> edge3 = afni.Edge3()
476+
>>> edge3.inputs.in_file = 'functional.nii'
477+
>>> edge3.inputs.out_file = 'edges.nii'
478+
>>> edge3.inputs.datum = 'byte'
479+
>>> edge3.cmdline # doctest: +ALLOW_UNICODE
480+
'3dedge3 -input functional.nii -datum byte -prefix edges.nii'
481+
>>> res = edge3.run() # doctest: +SKIP
482+
483+
"""
484+
485+
_cmd = '3dedge3'
486+
input_spec = Edge3InputSpec
487+
output_spec = AFNICommandOutputSpec
488+
489+
397490
class EvalInputSpec(AFNICommandInputSpec):
398491
in_file_a = File(
399492
desc='input file to 1deval',

0 commit comments

Comments
 (0)