Skip to content

Commit f77fb3e

Browse files
Added JacobianDeterminant interface
1 parent d9908ea commit f77fb3e

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

CHANGES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Next release
22
============
33

44
* ENH: Add basic support for LSF plugin.
5-
* ENH: New interfaces: ICC, Meshfix, ants.Register
5+
* ENH: New interfaces: ICC, Meshfix, ants.Register, ants.JacobianDeterminant
66
* ENH: New workflows: ants template building (both using 'ANTS' and the new 'antsRegistration')
77
* ENH: New examples: how to use ANTS template building workflows (smri_ants_build_tmeplate),
88
how to set SGE specific options (smri_ants_build_template_new)

nipype/interfaces/ants/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
from .segmentation import Atropos, N4BiasFieldCorrection
1515

1616
# Utility Programs
17-
from .utils import AverageAffineTransform, AverageImages, MultiplyImages
17+
from .utils import AverageAffineTransform, AverageImages, MultiplyImages, JacobianDeterminant

nipype/interfaces/ants/utils.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,54 @@ def _list_outputs(self):
117117
outputs = self._outputs().get()
118118
outputs['output_product_image'] = os.path.abspath(self.inputs.output_product_image)
119119
return outputs
120+
121+
122+
class JacobianDeterminantInputSpec(ANTSCommandInputSpec):
123+
dimension = traits.Enum(3, 2, argstr='%d', usedefault=False, mandatory=True, position=0, desc='image dimension (2 or 3)')
124+
warp_file = File(argstr='%s', exists=True, mandatory=True, position=1, desc='input warp file')
125+
output_prefix = File(argstr='%s', genfile=True, hash_files=False, position=2, desc='prefix of the output image filename: PREFIX(log)jacobian.nii.gz')
126+
use_log = traits.Enum(0, 1, argstr='%d', mandatory=False, position=3, desc='log transform the jacobian determinant')
127+
template_mask = File(argstr='%s', exists=True, mandatory=False, position=4, desc='template mask to adjust for head size')
128+
norm_by_total = traits.Enum(0, 1, argstr='%d', mandatory=False, position=5, desc='normalize jacobian by total in mask to adjust for head size')
129+
projection_vector = traits.List(traits.Float(), argstr='%s', sep='x', mandatory=False, position=6, desc='vector to project warp against')
130+
131+
class JacobianDeterminantOutputSpec(TraitedSpec):
132+
jacobian_image = File(exists=True, desc='(log transformed) jacobian image')
133+
134+
class JacobianDeterminant(ANTSCommand):
135+
"""
136+
Examples
137+
--------
138+
>>> from nipype.interfaces.ants import JacobianDeterminant
139+
>>> jacobian = JacobianDeterminant()
140+
>>> jacobian.inputs.dimension = 3
141+
>>> jacobian.inputs.warp_file = 'Sub001_2Warp.nii'
142+
>>> jacobian.inputs.output_prefix = 'Sub001_'
143+
>>> jacobian.inputs.use_log = 1
144+
>>> jacobian.cmdline
145+
'ANTSJacobian 3 xyz_2Warp.nii.gz xyz_ 1'
146+
"""
147+
148+
_cmd = 'ANTSJacobian'
149+
input_spec = JacobianDeterminantInputSpec
150+
output_spec = JacobianDeterminantOutputSpec
151+
152+
# def _format_arg(self, opt, spec, val):
153+
# return super(JacobianDeterminant, self)._format_arg(opt, spec, val)
154+
155+
def _gen_filename(self, name):
156+
if name == 'output_prefix':
157+
output = self.inputs.output_prefix
158+
if not isdefined(output):
159+
_, name, ext = split_filename(self.inputs.warp_file)
160+
output = name + '_'
161+
return output
162+
return None
163+
164+
def _list_outputs(self):
165+
outputs = self._outputs().get()
166+
if self.inputs.use_log == 1:
167+
outputs['jacobian_image'] = os.path.abspath(self._gen_filename('output_prefix') + 'logjacobian.nii.gz')
168+
else:
169+
outputs['jacobian_image'] = os.path.abspath(self._gen_filename('output_prefix') + 'jacobian.nii.gz')
170+
return outputs

0 commit comments

Comments
 (0)