|
| 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 | + }] |
0 commit comments