|
1 |
| -from nipype.interfaces.base import CommandLineInputSpec, File, traits, TraitedSpec |
| 1 | +from nipype.interfaces.base import CommandLineInputSpec, File, traits, TraitedSpec, Str |
2 | 2 | from nipype.interfaces.workbench.base import WBCommand
|
3 | 3 |
|
4 | 4 |
|
@@ -384,3 +384,52 @@ def _format_arg(self, opt, spec, val):
|
384 | 384 | self.inputs.flirt_target_volume or self.inputs.volume_space,
|
385 | 385 | )
|
386 | 386 | 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