/
patchmatch.py
110 lines (84 loc) · 3.3 KB
/
patchmatch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""
The fusion module provides higher-level interfaces to some of the operations
that can be performed with the seg_DetectLesions command-line program.
"""
import warnings
from ..base import TraitedSpec, File, traits, CommandLineInputSpec
from .base import NiftySegCommand
from ..niftyreg.base import get_custom_path
warn = warnings.warn
warnings.filterwarnings("always", category=UserWarning)
class PatchMatchInputSpec(CommandLineInputSpec):
"""Input Spec for PatchMatch."""
# Mandatory input arguments
in_file = File(
argstr="-i %s",
exists=True,
mandatory=True,
desc="Input image to segment",
position=1,
)
mask_file = File(
argstr="-m %s",
exists=True,
mandatory=True,
desc="Input mask for the area where applies PatchMatch",
position=2,
)
database_file = File(
argstr="-db %s",
exists=True,
mandatory=True,
desc="Database with the segmentations",
position=3,
)
# Output file name
out_file = File(
name_source=["in_file"],
name_template="%s_pm.nii.gz",
desc="The output filename of the patchmatch results",
argstr="-o %s",
position=4,
)
# Optional arguments
patch_size = traits.Int(desc="Patch size, #voxels", argstr="-size %i")
desc = "Constrained search area size, number of times bigger than the \
patchsize"
cs_size = traits.Int(desc=desc, argstr="-cs %i")
match_num = traits.Int(desc="Number of better matching", argstr="-match %i")
pm_num = traits.Int(desc="Number of patchmatch executions", argstr="-pm %i")
desc = "Number of iterations for the patchmatch algorithm"
it_num = traits.Int(desc=desc, argstr="-it %i")
class PatchMatchOutputSpec(TraitedSpec):
"""OutputSpec for PatchMatch."""
out_file = File(desc="Output segmentation")
class PatchMatch(NiftySegCommand):
"""Interface for executable seg_PatchMatch from NiftySeg platform.
The database file is a text file and in each line we have a template
file, a mask with the search region to consider and a file with the
label to propagate.
Input image, input mask, template images from database and masks from
database must have the same 4D resolution (same number of XxYxZ voxels,
modalities and/or time-points).
Label files from database must have the same 3D resolution
(XxYxZ voxels) than input image but can have different number of
volumes than the input image allowing to propagate multiple labels
in the same execution.
`Source code <http://cmictig.cs.ucl.ac.uk/wiki/index.php/NiftySeg>`_ |
`Documentation <http://cmictig.cs.ucl.ac.uk/wiki/index.php/NiftySeg_documentation>`_
Examples
--------
>>> from nipype.interfaces import niftyseg
>>> node = niftyseg.PatchMatch()
>>> node.inputs.in_file = 'im1.nii'
>>> node.inputs.mask_file = 'im2.nii'
>>> node.inputs.database_file = 'db.xml'
>>> node.cmdline
'seg_PatchMatch -i im1.nii -m im2.nii -db db.xml -o im1_pm.nii.gz'
"""
_cmd = get_custom_path("seg_PatchMatch", env_dir="NIFTYSEGDIR")
input_spec = PatchMatchInputSpec
output_spec = PatchMatchOutputSpec
_suffix = "_pm"