Skip to content

Commit 15f520d

Browse files
authored
Merge pull request #1845 from alexsavio/direct
Add ANTs' KellyKapowski interface
2 parents 0fba4cf + ad48e19 commit 15f520d

File tree

1 file changed

+158
-0
lines changed

1 file changed

+158
-0
lines changed

nipype/interfaces/ants/segmentation.py

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from builtins import range, str
1313

1414
import os
15+
from ...external.due import BibTeX
1516
from ...utils.filemanip import split_filename, copyfile
1617
from ..base import TraitedSpec, File, traits, InputMultiPath, OutputMultiPath, isdefined
1718
from .base import ANTSCommand, ANTSCommandInputSpec
@@ -1171,3 +1172,160 @@ def _list_outputs(self):
11711172
self.inputs.out_atlas_voting_weight_name_format)
11721173

11731174
return outputs
1175+
1176+
1177+
class KellyKapowskiInputSpec(ANTSCommandInputSpec):
1178+
dimension = traits.Enum(3, 2, argstr='--image-dimensionality %d', usedefault=True,
1179+
desc='image dimension (2 or 3)')
1180+
1181+
segmentation_image = File(exists=True, argstr='--segmentation-image "%s"', mandatory=True,
1182+
desc="A segmentation image must be supplied labeling the gray and white matters.\n"
1183+
"Default values = 2 and 3, respectively.",)
1184+
1185+
gray_matter_label = traits.Int(2, usedefault=True,
1186+
desc="The label value for the gray matter label in the segmentation_image.")
1187+
1188+
white_matter_label = traits.Int(3, usedefault=True,
1189+
desc="The label value for the white matter label in the segmentation_image.")
1190+
1191+
gray_matter_prob_image = File(exists=True, argstr='--gray-matter-probability-image "%s"',
1192+
desc="In addition to the segmentation image, a gray matter probability image can be\n"
1193+
"used. If no such image is supplied, one is created using the segmentation image\n"
1194+
"and a variance of 1.0 mm.")
1195+
1196+
white_matter_prob_image = File(exists=True, argstr='--white-matter-probability-image "%s"',
1197+
desc="In addition to the segmentation image, a white matter probability image can be\n"
1198+
"used. If no such image is supplied, one is created using the segmentation image\n"
1199+
"and a variance of 1.0 mm.")
1200+
1201+
convergence = traits.Str(default="[50,0.001,10]", argstr='--convergence "%s"', usedefault=True,
1202+
desc="Convergence is determined by fitting a line to the normalized energy profile of\n"
1203+
"the last N iterations (where N is specified by the window size) and determining\n"
1204+
"the slope which is then compared with the convergence threshold.",)
1205+
1206+
thickness_prior_estimate = traits.Float(10, usedefault=True, argstr="--thickness-prior-estimate %f",
1207+
desc="Provides a prior constraint on the final thickness measurement in mm.")
1208+
1209+
thickness_prior_image = File(exists=True, argstr='--thickness-prior-image "%s"',
1210+
desc="An image containing spatially varying prior thickness values.")
1211+
1212+
gradient_step = traits.Float(0.025, usedefault=True, argstr="--gradient-step %f",
1213+
desc="Gradient step size for the optimization.")
1214+
1215+
smoothing_variance = traits.Float(1.0, argstr="--smoothing-variance %f",
1216+
desc="Defines the Gaussian smoothing of the hit and total images.")
1217+
1218+
smoothing_velocity_field = traits.Float(1.5, argstr="--smoothing-velocity-field-parameter %f",
1219+
desc="Defines the Gaussian smoothing of the velocity field (default = 1.5).\n"
1220+
"If the b-spline smoothing option is chosen, then this defines the \n"
1221+
"isotropic mesh spacing for the smoothing spline (default = 15).")
1222+
1223+
use_bspline_smoothing = traits.Bool(argstr="--use-bspline-smoothing 1",
1224+
desc="Sets the option for B-spline smoothing of the velocity field.")
1225+
1226+
number_integration_points = traits.Int(10, argstr="--number-of-integration-points %d",
1227+
desc="Number of compositions of the diffeomorphism per iteration.")
1228+
1229+
max_invert_displacement_field_iters = traits.Int(20, argstr="--maximum-number-of-invert-displacement-field-iterations %d",
1230+
desc="Maximum number of iterations for estimating the invert \n"
1231+
"displacement field.")
1232+
1233+
cortical_thickness = File(argstr='--output "%s"', keep_extension=True,
1234+
name_source=["segmentation_image"], name_template='%s_cortical_thickness',
1235+
desc='Filename for the cortical thickness.', hash_files=False)
1236+
1237+
warped_white_matter = File(name_source=["segmentation_image"], keep_extension=True,
1238+
name_template='%s_warped_white_matter',
1239+
desc='Filename for the warped white matter file.', hash_files=False)
1240+
1241+
1242+
class KellyKapowskiOutputSpec(TraitedSpec):
1243+
cortical_thickness = File(desc="A thickness map defined in the segmented gray matter.")
1244+
warped_white_matter = File(desc="A warped white matter image.")
1245+
1246+
1247+
class KellyKapowski(ANTSCommand):
1248+
""" Nipype Interface to ANTs' KellyKapowski, also known as DiReCT.
1249+
1250+
DiReCT is a registration based estimate of cortical thickness. It was published
1251+
in S. R. Das, B. B. Avants, M. Grossman, and J. C. Gee, Registration based
1252+
cortical thickness measurement, Neuroimage 2009, 45:867--879.
1253+
1254+
Examples
1255+
--------
1256+
>>> from nipype.interfaces.ants.segmentation import KellyKapowski
1257+
>>> kk = KellyKapowski()
1258+
>>> kk.inputs.dimension = 3
1259+
>>> kk.inputs.segmentation_image = "segmentation0.nii.gz"
1260+
>>> kk.inputs.convergence = "[45,0.0,10]"
1261+
>>> kk.inputs.gradient_step = 0.025
1262+
>>> kk.inputs.smoothing_variance = 1.0
1263+
>>> kk.inputs.smoothing_velocity_field = 1.5
1264+
>>> #kk.inputs.use_bspline_smoothing = False
1265+
>>> kk.inputs.number_integration_points = 10
1266+
>>> kk.inputs.thickness_prior_estimate = 10
1267+
>>> kk.cmdline # doctest: +ALLOW_UNICODE
1268+
u'KellyKapowski --convergence "[45,0.0,10]" \
1269+
--output "[segmentation0_cortical_thickness.nii.gz,segmentation0_warped_white_matter.nii.gz]" \
1270+
--image-dimensionality 3 --gradient-step 0.025000 --number-of-integration-points 10 \
1271+
--segmentation-image "[segmentation0.nii.gz,2,3]" --smoothing-variance 1.000000 \
1272+
--smoothing-velocity-field-parameter 1.500000 --thickness-prior-estimate 10.000000'
1273+
1274+
"""
1275+
_cmd = "KellyKapowski"
1276+
input_spec = KellyKapowskiInputSpec
1277+
output_spec = KellyKapowskiOutputSpec
1278+
1279+
references_ = [{'entry': BibTeX("@book{Das2009867,"
1280+
"author={Sandhitsu R. Das and Brian B. Avants and Murray Grossman and James C. Gee},"
1281+
"title={Registration based cortical thickness measurement.},"
1282+
"journal={NeuroImage},"
1283+
"volume={45},"
1284+
"number={37},"
1285+
"pages={867--879},"
1286+
"year={2009},"
1287+
"issn={1053-8119},"
1288+
"url={http://www.sciencedirect.com/science/article/pii/S1053811908012780},"
1289+
"doi={http://dx.doi.org/10.1016/j.neuroimage.2008.12.016}"
1290+
"}"),
1291+
'description': 'The details on the implementation of DiReCT.',
1292+
'tags': ['implementation'],
1293+
}]
1294+
1295+
def _parse_inputs(self, skip=None):
1296+
if skip is None:
1297+
skip = []
1298+
skip += ['warped_white_matter', 'gray_matter_label', 'white_matter_label']
1299+
return super(KellyKapowski, self)._parse_inputs(skip=skip)
1300+
1301+
def _gen_filename(self, name):
1302+
if name == 'cortical_thickness':
1303+
output = self.inputs.cortical_thickness
1304+
if not isdefined(output):
1305+
_, name, ext = split_filename(self.inputs.segmentation_image)
1306+
output = name + '_cortical_thickness' + ext
1307+
return output
1308+
1309+
if name == 'warped_white_matter':
1310+
output = self.inputs.warped_white_matter
1311+
if not isdefined(output):
1312+
_, name, ext = split_filename(self.inputs.segmentation_image)
1313+
output = name + '_warped_white_matter' + ext
1314+
return output
1315+
1316+
return None
1317+
1318+
def _format_arg(self, opt, spec, val):
1319+
if opt == "segmentation_image":
1320+
newval = '[{0},{1},{2}]'.format(self.inputs.segmentation_image,
1321+
self.inputs.gray_matter_label,
1322+
self.inputs.white_matter_label)
1323+
return spec.argstr % newval
1324+
1325+
if opt == "cortical_thickness":
1326+
ct = self._gen_filename("cortical_thickness")
1327+
wm = self._gen_filename("warped_white_matter")
1328+
newval = '[{},{}]'.format(ct, wm)
1329+
return spec.argstr % newval
1330+
1331+
return super(KellyKapowski, self)._format_arg(opt, spec, val)

0 commit comments

Comments
 (0)