class RegAladin(NIFTYREGCommand): """ Use RegAladin to perform linear (rigid or affine) image registration. Examples -------- >>> from nipype.interfaces import niftyreg >>> aladin = niftyreg.RegAladin() >>> aladin.inputs.flo_image = "floating_image.nii.gz" >>> aladin.inputs.ref_image = "reference_image.nii.gz" """ _cmd = getNiftyRegPath('reg_aladin') input_spec = RegAladinInputSpec output_spec = RegAladinOutputSpec def _gen_filename(self, name): if name == 'aff_file': return self._gen_fname(self.inputs.flo_file, suffix='_aff', change_ext=True, ext='.txt') return None def _list_outputs(self): outputs = super(RegAladin, self)._list_outputs() if isdefined(self.inputs.aff_file): outputs['aff_file'] = self.inputs.aff_file else: outputs['aff_file'] = self._gen_filename('aff_file') # Make a list of the linear transformation file and the input image outputs['avg_output'] = os.path.abspath( outputs['aff_file']) + ' ' + os.path.abspath(self.inputs.flo_file) return outputs
class RegAverage(NIFTYREGCommand): """ Use RegAverage to average a set of transformations, images or both. Examples -------- >>> from nipype.interfaces import niftyreg >>> reg_average = niftyreg.RegAverage() >>> """ _cmd = getNiftyRegPath('reg_average') input_spec = RegAverageInputSpec output_spec = RegAverageOutputSpec def _gen_filename(self, name): if name == 'out_file': return self._gen_fname('average_output', ext='.nii.gz') return None def _list_outputs(self): outputs = self.output_spec().get() if isdefined(self.inputs.out_file): outputs['out_file'] = self.inputs.out_file else: outputs['out_file'] = self._gen_filename('out_file') return outputs
class RegResample(NIFTYREGCommand): _cmd = getNiftyRegPath('reg_resample') input_spec = RegResampleInputSpec output_spec = RegResampleOutputSpec # Need this overload to properly constraint the interpolation type input def _format_arg(self, name, spec, value): if name == 'inter_val': return spec.argstr % { 'NN': 0, 'LIN': 1, 'CUB': 3, 'SINC': 5 }[value] else: return super(RegResample, self)._format_arg(name, spec, value)
class RegF3D(NIFTYREGCommand): _cmd = getNiftyRegPath('reg_f3d') input_spec = RegF3DInputSpec output_spec = RegF3DOutputSpec def _get_basename_without_extension(self, in_file): ret = os.path.basename(in_file) ret = ret.replace('.nii.gz', '') ret = ret.replace('.nii', '') ret = ret.replace('.img.gz', '') ret = ret.replace('.img.bz2', '') ret = ret.replace('.img', '') ret = ret.replace('.hdr', '') return ret def _list_outputs(self): outputs = super(RegF3D, self)._list_outputs() basename = self._get_basename_without_extension(outputs['cpp_file']) outputs['invcpp_file'] = os.path.abspath(basename + '_backward.nii.gz') # Make a list of the linear transformation file and the input image outputs['avg_output'] = os.path.abspath( outputs['cpp_file']) + ' ' + os.path.abspath(self.inputs.flo_file) return outputs
class RegTransform(NIFTYREGCommand): """ * * OPTIONS * * -v Print the subversion revision number -ref <filename> Filename of the reference image The Reference image has to be specified when a cubic B-Spline parametrised control point grid is used*. -ref2 <filename> Filename of the second reference image to be used when dealing with composition -def <filename1> <filename2> Take a transformation of any recognised type* and compute the corresponding deformation field filename1 - Input transformation file name filename2 - Output deformation field file name -disp <filename1> <filename2> Take a transformation of any recognised type* and compute the corresponding displacement field filename1 - Input transformation file name filename2 - Output displacement field file name -flow <filename1> <filename2> Take a spline parametrised SVF and compute the corresponding flow field filename1 - Input transformation file name filename2 - Output flow field file name -comp <filename1> <filename2> <filename3> Compose two transformations of any recognised type* and returns a deformation field. Trans3(x) = Trans2(Trans1(x)). filename1 - Input transformation 1 file name (associated with -ref if required) filename2 - Input transformation 2 file name (associated with -ref2 if required) filename3 - Output deformation field file name -updSform <filename1> <filename2> <filename3> Update the sform of an image using an affine transformation. Filename1 - Image to be updated Filename2 - Affine transformation defined as Affine x Reference = Floating Filename3 - Updated image. -invAff <filename1> <filename2> Invert an affine matrix. filename1 - Input affine transformation file name filename2 - Output inverted affine transformation file name -invNrr <filename1> <filename2> <filename3> Invert a non-rigid transformation and save the result as a deformation field. filename1 - Input transformation file name filename2 - Input floating (source) image where the inverted transformation is defined filename3 - Output inverted transformation file name Note that the cubic b-spline grid parametrisations can not be inverted without approximation, as a result, they are converted into deformation fields before inversion. -half <filename1> <filename2> The input transformation is halfed and stored using the same transformation type. filename1 - Input transformation file name filename2 - Output transformation file name -makeAff <rx> <ry> <rz> <tx> <ty> <tz> <sx> <sy> <sz> <shx> <shy> <shz> <outputFilename> Create an affine transformation matrix -aff2rig <filename1> <filename2> Extract the rigid component from an affine transformation matrix filename1 - Input transformation file name filename2 - Output transformation file name -flirtAff2NR <filename1> <filename2> <filename3> <filename4> Convert a flirt (FSL) affine transformation to a NiftyReg affine transformation filename1 - Input FLIRT (FSL) affine transformation file name filename2 - Image used as a reference (-ref arg in FLIRT) filename3 - Image used as a floating (-in arg in FLIRT) filename4 - Output affine transformation file name * The supported transformation types are: - cubic B-Spline parametrised grid (reference image is required) - a dense deformation field - a dense displacement field - a cubic B-Spline parametrised stationary velocity field (reference image is required) - a stationary velocity deformation field - a stationary velocity displacement field - an affine matrix * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * """ _cmd = getNiftyRegPath('reg_transform') input_spec = RegTransformInputSpec output_spec = RegTransformOutputSpec _suffix = '_reg_transform' def _find_input(self): inputs = [ self.inputs.def_input, self.inputs.disp_input, self.inputs.flow_input, self.inputs.comp_input, self.inputs.comp_input2, self.inputs.upd_s_form_input2, self.inputs.inv_aff_input, self.inputs.inv_nrr_input, self.inputs.half_input, self.inputs.make_aff_input, self.inputs.aff_2_rig_input, self.inputs.flirt_2_nr_input ] entries = [] for entry in inputs: if isdefined(entry): entries.append(entry) _, _, ext = split_filename(entry) if ext == '.nii' or ext == '.nii.gz' or ext == '.hdr': return entry if len(entries): return entries[0] return None def _gen_filename(self, name): if name == 'out_file': input_to_use = self._find_input() _, base, ext = split_filename(input_to_use) return self._gen_fname(input_to_use, suffix=self._suffix, change_ext=True, ext=ext) return None def _list_outputs(self): outputs = self.output_spec().get() if isdefined(self.inputs.out_file): outputs['out_file'] = self.inputs.out_file outputs['out_file'] = os.path.abspath(outputs['out_file']) else: outputs['out_file'] = self._gen_filename('out_file') return outputs
class RegTools(NIFTYREGCommand): _cmd = getNiftyRegPath('reg_tools') input_spec = RegToolsInputSpec output_spec = RegToolsOutputSpec
class RegJacobian(NIFTYREGCommand): _cmd = getNiftyRegPath('reg_jacobian') input_spec = RegJacobianInputSpec output_spec = RegJacobianOutputSpec _suffix = '_jacobian_'
class RegMeasure(NIFTYREGCommand): _cmd = getNiftyRegPath('reg_measure') input_spec = RegMeasureInputSpec output_spec = RegMeasureOutputSpec