-
Notifications
You must be signed in to change notification settings - Fork 533
WIP: antsRegistrationSyNQuick.sh wrapper #1392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -975,3 +975,89 @@ def _list_outputs(self): | |
if len(self.inputs.save_state): | ||
outputs['save_state'] = os.path.abspath(self.inputs.save_state) | ||
return outputs | ||
|
||
|
||
|
||
|
||
|
||
class RegistrationSynQuickInputSpec(ANTSCommandInputSpec): | ||
dimension = traits.Enum(3, 2, argstr='-d %d', | ||
usedefault=True, desc='image dimension (2 or 3)') | ||
fixed_image = InputMultiPath(File(exists=True), mandatory=True, argstr='-f %s', | ||
desc='Fixed image or source image or reference image') | ||
moving_image = InputMultiPath(File(exists=True), mandatory=True, argstr='-m %s', | ||
desc='Moving image or target image') | ||
output_prefix = traits.Str("transform", usedefault=True, argstr='-o %s', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
desc="A prefix that is prepended to all output files") | ||
|
||
# todo ANTSCommandInputSpec already has this, but I can't figure out how to set it without defining it again | ||
num_threads = traits.Int(default_value=1, desc='Number of threads (default = 1)', argstr='-n %d') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not 100% sure, but I think you can do |
||
|
||
transform_type = traits.Enum('s', 't', 'r', 'a', 'sr', 'b', 'br', argstr='-t %s', | ||
desc='transform type\n\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use block strings: transform_type = traits.Enum('s', 't', 'r', 'a', 'sr', 'b', 'br', argstr='-t %s',
usedefault=True, desc="""\
transform type -
t: translation
r: rigid
a: rigid + affine
s: rigid + affine + deformable syn (default)
sr: rigid + deformable syn
b: rigid + affine + deformable b-spline syn
br: rigid + deformable b-spline syn""") |
||
t: translation\ | ||
r: rigid \n\ | ||
a: rigid + affine\n\ | ||
s: rigid + affine + deformable syn (default)\ | ||
sr: rigid + deformable syn\ | ||
b: rigid + affine + deformable b-spline syn\n\ | ||
br: rigid + deformable b-spline syn', | ||
usedefault=True) | ||
|
||
use_histogram_matching = traits.Bool(default=False, argstr='-j %s', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
additionally: you may remove the |
||
desc='use histogram matching') | ||
histogram_bins = traits.Int(default_value=32, argstr='-r %d', | ||
desc='histogram bins for mutual information in SyN stage \ | ||
(default = 32)') | ||
spline_distance = traits.Int(default_value=26, argstr='-s %d', | ||
desc='spline distance for deformable B-spline SyN transform \ | ||
(default = 26)') | ||
precision_type = traits.Enum('double', 'float', argstr='-p %s', | ||
desc='precision type (default = double)', usedefault=True) | ||
|
||
|
||
class RegistrationSynQuickOutputSpec(TraitedSpec): | ||
warped_image = File(exists=True, desc="Warped image") | ||
inverse_warped_image = File(exists=True, desc="Inverse warped image") | ||
out_matrix = File(exists=True, desc='Affine matrix') | ||
forward_warp_field = File(exists=True, desc='Forward warp field') | ||
inverse_warp_field = File(exists=True, desc='Inverse warp field') | ||
|
||
|
||
class RegistrationSynQuick(ANTSCommand): | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing brief summary |
||
Examples | ||
-------- | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing doctest |
||
""" | ||
# todo examples | ||
|
||
_cmd = 'antsRegistrationSynQuick.sh' | ||
input_spec = RegistrationSynQuickInputSpec | ||
output_spec = RegistrationSynQuickOutputSpec | ||
|
||
def _format_arg(self, name, spec, value): | ||
if name == 'use_histogram_matching': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use |
||
if isdefined(self.inputs.use_histogram_matching): | ||
return spec.argstr % {False: '0', True: '1'}[value] | ||
|
||
elif name == 'precision_type': | ||
if isdefined(self.inputs.precision_type): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is always |
||
return spec.argstr % {'float': 'f', 'double': 'd'}[value] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return super(RegistrationSynQuick, self)._format_arg(name, spec, value) | ||
|
||
def _list_outputs(self): | ||
outputs = self.output_spec().get() | ||
outputs['warped_image'] = os.path.abspath(self.inputs.output_prefix + 'Warped.nii.gz') | ||
outputs['inverse_warped_image'] = os.path.abspath( | ||
self.inputs.output_prefix + 'InverseWarped.nii.gz') | ||
outputs['out_matrix'] = os.path.abspath(self.inputs.output_prefix + '0GenericAffine.mat') | ||
|
||
# todo in the case of linear transformation-only there won't be fields. is there a more elegant way to specify that? | ||
if self.inputs.transform_type not in ('t', 'r', 'a'): | ||
outputs['forward_warp_field'] = os.path.abspath( | ||
self.inputs.output_prefix + '1Warp.nii.gz') | ||
outputs['inverse_warp_field'] = os.path.abspath( | ||
self.inputs.output_prefix + '1InverseWarp.nii.gz') | ||
return outputs | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too many empty spaces (only 2 necessary)