Skip to content

Commit 88abb23

Browse files
authored
Merge pull request #2047 from effigies/enh/quickshear
ENH: Add Quickshear
2 parents b975793 + fbedb0f commit 88abb23

File tree

2 files changed

+132
-0
lines changed

2 files changed

+132
-0
lines changed

nipype/interfaces/quickshear.py

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# -*- coding: utf-8 -*-
2+
""" Quickshear is a simple geometric defacing algorithm
3+
4+
Change directory to provide relative paths for doctests
5+
>>> import os
6+
>>> filepath = os.path.dirname( os.path.realpath( __file__ ) )
7+
>>> datadir = os.path.realpath(os.path.join(filepath, '../testing/data'))
8+
>>> os.chdir(datadir)
9+
"""
10+
from __future__ import unicode_literals
11+
12+
from .base import CommandLineInputSpec, CommandLine, traits, TraitedSpec, File
13+
from ..external.due import BibTeX
14+
15+
16+
class QuickshearInputSpec(CommandLineInputSpec):
17+
in_file = File(exists=True, position=1, argstr='%s', mandatory=True,
18+
desc="neuroimage to deface")
19+
mask_file = File(exists=True, position=2, argstr='%s', desc="brain mask",
20+
mandatory=True)
21+
out_file = File(name_template="%s_defaced", name_source='in_file',
22+
position=3, argstr='%s', desc="defaced output image",
23+
keep_extension=True)
24+
buff = traits.Int(position=4, argstr='%d',
25+
desc='buffer size (in voxels) between shearing '
26+
'plane and the brain')
27+
28+
29+
class QuickshearOutputSpec(TraitedSpec):
30+
out_file = File(exists=True, desc="defaced output image")
31+
32+
33+
class Quickshear(CommandLine):
34+
"""
35+
Quickshear is a simple geometric defacing algorithm
36+
37+
Given an anatomical image and a reasonable brainmask, Quickshear estimates
38+
a shearing plane with the brain mask on one side and the face on the other,
39+
zeroing out the face side.
40+
41+
>>> from nipype.interfaces.quickshear import Quickshear
42+
>>> qs = Quickshear(in_file='T1.nii', mask_file='brain_mask.nii')
43+
>>> qs.cmdline # doctest: +ALLOW_UNICODE
44+
'quickshear T1.nii brain_mask.nii T1_defaced.nii'
45+
46+
In the absence of a precomputed mask, a simple pipeline can be generated
47+
with any tool that generates brain masks:
48+
49+
>>> from nipype.pipeline import engine as pe
50+
>>> from nipype.interfaces import utility as niu
51+
>>> from nipype.interfaces.fsl import BET
52+
>>> deface_wf = pe.Workflow('deface_wf')
53+
>>> inputnode = pe.Node(niu.IdentityInterface(['in_file']),
54+
... name='inputnode')
55+
>>> outputnode = pe.Node(niu.IdentityInterface(['out_file']),
56+
... name='outputnode')
57+
>>> bet = pe.Node(BET(mask=True), name='bet')
58+
>>> quickshear = pe.Node(Quickshear(), name='quickshear')
59+
>>> deface_wf.connect([
60+
... (inputnode, bet, [('in_file', 'in_file')]),
61+
... (inputnode, quickshear, [('in_file', 'in_file')]),
62+
... (bet, quickshear, [('mask_file', 'mask_file')]),
63+
... (quickshear, outputnode, [('out_file', 'out_file')]),
64+
... ])
65+
>>> inputnode.inputs.in_file = 'T1.nii'
66+
>>> res = deface_wf.run() # doctest: +SKIP
67+
"""
68+
_cmd = 'quickshear'
69+
input_spec = QuickshearInputSpec
70+
output_spec = QuickshearOutputSpec
71+
72+
references_ = [
73+
{'entry':
74+
BibTeX('@inproceedings{Schimke2011,'
75+
'address = {San Francisco},'
76+
'author = {Schimke, Nakeisha and Hale, John},'
77+
'booktitle = {Proceedings of the 2nd USENIX Conference on '
78+
'Health Security and Privacy},'
79+
'title = {{Quickshear Defacing for Neuroimages}},'
80+
'year = {2011},'
81+
'month = sep}'),
82+
'tags': ['implementation'],
83+
}]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..quickshear import Quickshear
4+
5+
6+
def test_Quickshear_inputs():
7+
input_map = dict(args=dict(argstr='%s',
8+
),
9+
buff=dict(argstr='%d',
10+
position=4,
11+
),
12+
environ=dict(nohash=True,
13+
usedefault=True,
14+
),
15+
ignore_exception=dict(nohash=True,
16+
usedefault=True,
17+
),
18+
in_file=dict(argstr='%s',
19+
mandatory=True,
20+
position=1,
21+
),
22+
mask_file=dict(argstr='%s',
23+
mandatory=True,
24+
position=2,
25+
),
26+
out_file=dict(argstr='%s',
27+
keep_extension=True,
28+
name_source='in_file',
29+
name_template='%s_defaced',
30+
position=3,
31+
),
32+
terminal_output=dict(nohash=True,
33+
),
34+
)
35+
inputs = Quickshear.input_spec()
36+
37+
for key, metadata in list(input_map.items()):
38+
for metakey, value in list(metadata.items()):
39+
assert getattr(inputs.traits()[key], metakey) == value
40+
41+
42+
def test_Quickshear_outputs():
43+
output_map = dict(out_file=dict(),
44+
)
45+
outputs = Quickshear.output_spec()
46+
47+
for key, metadata in list(output_map.items()):
48+
for metakey, value in list(metadata.items()):
49+
assert getattr(outputs.traits()[key], metakey) == value

0 commit comments

Comments
 (0)