Skip to content

Commit 65e492a

Browse files
committed
ENH: Add VolumeAllLabelsToROIs
1 parent e61efb5 commit 65e492a

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

nibabies/interfaces/conftest.py

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'T1w.nii',
1212
'rois.nii',
1313
'func_to_struct.mat',
14+
'labels.nii',
1415
'sub-01_run-01_echo-1_bold.nii.gz',
1516
'sub-01_run-01_echo-2_bold.nii.gz',
1617
'sub-01_run-01_echo-3_bold.nii.gz',

nibabies/interfaces/workbench.py

+50-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from nipype.interfaces.base import CommandLineInputSpec, File, traits, TraitedSpec
1+
from nipype.interfaces.base import CommandLineInputSpec, File, traits, TraitedSpec, Str
22
from nipype.interfaces.workbench.base import WBCommand
33

44

@@ -384,3 +384,52 @@ def _format_arg(self, opt, spec, val):
384384
self.inputs.flirt_target_volume or self.inputs.volume_space,
385385
)
386386
return super()._format_arg(opt, spec, val)
387+
388+
389+
class VolumeAllLabelsToROIsInputSpec(CommandLineInputSpec):
390+
in_file = File(
391+
exists=True,
392+
mandatory=True,
393+
argstr="%s",
394+
position=0,
395+
desc="the input volume label file",
396+
)
397+
label_map = traits.Either(
398+
traits.Int, Str,
399+
mandatory=True,
400+
argstr="%s",
401+
position=1,
402+
desc="the number or name of the label map to use",
403+
)
404+
out_file = File(
405+
name_source=["in_file"],
406+
name_template="%s_rois.nii.gz",
407+
argstr="%s",
408+
position=2,
409+
desc="the output volume",
410+
)
411+
412+
413+
class VolumeAllLabelsToROIsOutputSpec(TraitedSpec):
414+
out_file = File(exists=True, desc="the output volume")
415+
416+
417+
class VolumeAllLabelsToROIs(WBCommand):
418+
"""
419+
Make ROIs from all labels in a volume frame
420+
421+
The output volume has a frame for each label in the specified input
422+
frame, other than the ??? label, each of which contains an ROI of all
423+
voxels that are set to the corresponding label.
424+
425+
>>> from nibabies.interfaces.workbench import VolumeAllLabelsToROIs
426+
>>> rois = VolumeAllLabelsToROIs()
427+
>>> rois.inputs.in_file = data_dir / 'labels.nii'
428+
>>> rois.inputs.label_map = 1
429+
>>> rois.cmdline #doctest: +ELLIPSIS
430+
'wb_command -volume-all-labels-to-rois .../labels.nii 1 labels_rois.nii.gz'
431+
"""
432+
433+
input_spec = VolumeAllLabelsToROIsInputSpec
434+
output_spec = VolumeAllLabelsToROIsOutputSpec
435+
_cmd = "wb_command -volume-all-labels-to-rois"

0 commit comments

Comments
 (0)