Skip to content

Commit 68d67a4

Browse files
committed
Added robex segment interface
1 parent 79132b5 commit 68d67a4

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

nipype/interfaces/robex/__init__.py

Whitespace-only changes.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import os
2+
from pathlib import Path
3+
4+
from nipype.interfaces.base import (
5+
TraitedSpec,
6+
CommandLineInputSpec,
7+
CommandLine,
8+
File,
9+
traits, isdefined
10+
)
11+
from nipype.utils.filemanip import split_filename
12+
13+
14+
class RobexInputSpec(CommandLineInputSpec):
15+
in_file = File(desc="Input volume", exists=True,
16+
mandatory=True, position=0, argstr="%s")
17+
out_file = File(desc="Output volume", position=1, argstr="%s",
18+
hash_files=False, name_template='%s_brain', keep_extension=True)
19+
out_mask = File(desc="Output mask", position=2, argstr="%s",
20+
hash_files=False, name_template='%s_brainmask', keep_extension=True)
21+
seed = traits.Int(desc="Seed for random number generator", position=3, argstr="%i")
22+
23+
24+
class RobexOutputSpec(TraitedSpec):
25+
out_file = File(desc="Output volume", exists=True)
26+
out_mask = File(desc="Output mask", exists=True)
27+
28+
29+
class RobexSegment(CommandLine):
30+
"""
31+
32+
ROBEX is an automatic whole-brain extraction tool for T1-weighted MRI data (commonly known as skull stripping).
33+
ROBEX aims for robust skull-stripping across datasets with no parameter settings. It fits a triangular mesh,
34+
constrained by a shape model, to the probabilistic output of a supervised brain boundary classifier.
35+
Because the shape model cannot perfectly accommodate unseen cases, a small free deformation is subsequently allowed.
36+
The deformation is optimized using graph cuts.
37+
The method ROBEX is based on was published in IEEE Transactions on Medical Imaging;
38+
please visit the website http://www.jeiglesias.com to download the paper.
39+
40+
Examples
41+
--------
42+
>>> path_mr = 'structural.nii'
43+
>>> robex = RobexSegment(in_file=path_mr)
44+
>>> robex.run() # doctest: +SKIP
45+
46+
"""
47+
48+
input_spec = RobexInputSpec
49+
output_spec = RobexOutputSpec
50+
_cmd = 'runROBEX.sh'
51+
52+
def _format_arg(self, name, trait_spec, value):
53+
if name == "out_file" or name == "out_mask":
54+
if Path(value).name == value:
55+
value = os.path.join(os.getcwd(), Path(value).name)
56+
setattr(self.inputs, name, value)
57+
return super(RobexSegment, self)._format_arg(name, trait_spec, value)
58+
59+
def _list_outputs(self):
60+
outputs = self._outputs().get()
61+
outputs["out_file"] = self.inputs.out_file
62+
if isdefined(self.inputs.out_mask):
63+
outputs["out_mask"] = self.inputs.out_mask
64+
return outputs
65+
66+
def run(self, cwd=None, ignore_exception=None, **inputs):
67+
if not isdefined(self.inputs.out_file):
68+
_, base, extension = split_filename(self.inputs.in_file)
69+
self.inputs.out_file = base + "_brain_robex_" + extension
70+
return super(RobexSegment, self).run(cwd, ignore_exception, **inputs)

0 commit comments

Comments
 (0)