@@ -813,58 +813,89 @@ class DenoiseImageInputSpec(ANTSCommandInputSpec):
813813 'the input image can be resampled. The shrink '
814814 'factor, specified as a single integer, describes '
815815 'this resampling. Shrink factor = 1 is the default.' ))
816- output_image = traits .List (traits .Str (), argstr = "" ,
817- desc = 'The output consists of the noise corrected '
818- 'version of the input image. Optionally, one '
819- 'can also output the estimated noise image.' )
820- version = traits .Bool (False , argstr = "--version" , desc = ('Get version information.' ))
816+ output_image = traits .Str (argstr = "-o %s" , genfile = True , hash_files = False ,
817+ desc = 'The output consists of the noise corrected '
818+ 'version of the input image.' )
819+ save_noise = traits .Bool (False , mandatory = True , usedefault = True ,
820+ desc = ('True if the estimated noise should be saved '
821+ 'to file.' ), xor = ['noise_image' ])
822+ noise_image = File (desc = 'Filename for the estimated noise.' , hash_files = False )
821823 verbose = traits .Bool (False , argstr = "-v" , desc = ('Verbose output.' ))
822- short_help = traits .Bool (False , argstr = "-h" , desc = ('Print the help menu (short version).' ))
823- help = traits .Bool (False , argstr = "--help" , desc = ('Print the help menu.' ))
824824
825825
826826class DenoiseImageOutputSpec (TraitedSpec ):
827- output_corrected_image = File (exists = True )
828- output_noise_image = File (exists = True )
827+ output_image = File (exists = True )
828+ noise_image = File (exists = True )
829829
830830
831831class DenoiseImage (ANTSCommand ):
832832 """
833833 Examples
834834 --------
835+ >>> import copy
835836 >>> from nipype.interfaces.ants import DenoiseImage
836837 >>> denoise = DenoiseImage()
837838 >>> denoise.inputs.dimension = 3
838839 >>> denoise.inputs.input_image = 'im1.nii'
839- >>> denoise.inputs.output_image = ['output_corrected_image.nii.gz']
840840 >>> denoise.cmdline
841- 'DenoiseImage -d 3 -i im1.nii -n Gaussian -o output_corrected_image .nii.gz -s 1'
841+ 'DenoiseImage -d 3 -i im1.nii -n Gaussian -o im1_noise_corrected .nii -s 1'
842842
843- >>> denoise.inputs.noise_model = 'Rician'
844- >>> denoise.inputs.shrink_factor = 2
845- >>> denoise.cmdline
843+ >>> denoise_2 = copy.deepcopy(denoise)
844+ >>> denoise_2.inputs.output_image = 'output_corrected_image.nii.gz'
845+ >>> denoise_2.inputs.noise_model = 'Rician'
846+ >>> denoise_2.inputs.shrink_factor = 2
847+ >>> denoise_2.cmdline
846848 'DenoiseImage -d 3 -i im1.nii -n Rician -o output_corrected_image.nii.gz -s 2'
847849
848- >>> denoise.inputs.output_image = ['output_corrected_image.nii.gz', 'output_noise_image.nii.gz']
849- >>> denoise.cmdline
850- 'DenoiseImage -d 3 -i im1.nii -n Rician -o [output_corrected_image.nii.gz,output_noise_image.nii.gz] -s 2'
850+ >>> denoise_3 = DenoiseImage()
851+ >>> denoise_3.inputs.input_image = 'im1.nii'
852+ >>> denoise_3.inputs.save_noise = True
853+ >>> denoise_3.cmdline
854+ 'DenoiseImage -i im1.nii -n Gaussian -o [ im1_noise_corrected.nii, im1_noise.nii ] -s 1'
851855 """
852856 input_spec = DenoiseImageInputSpec
853857 output_spec = DenoiseImageOutputSpec
854858 _cmd = 'DenoiseImage'
855859
856- def _format_arg (self , opt , spec , val ):
857- if opt == 'output_image' :
858- if len (val ) == 1 :
859- retval = '-o {0}' .format (val [0 ])
860- elif len (val ) == 2 :
861- retval = '-o [{0},{1}]' .format (val [0 ], val [1 ])
862- return retval
863- return super (ANTSCommand , self )._format_arg (opt , spec , val )
860+ def _gen_filename (self , name ):
861+ if name == 'output_image' :
862+ output = self .inputs .output_image
863+ if not isdefined (output ):
864+ _ , name , ext = split_filename (self .inputs .input_image )
865+ output = name + '_noise_corrected' + ext
866+ return output
867+
868+ if name == 'noise_image' :
869+ output = self .inputs .noise_image
870+ if not isdefined (output ):
871+ _ , name , ext = split_filename (self .inputs .input_image )
872+ output = name + '_noise' + ext
873+ return output
874+ return None
875+
876+ def _format_arg (self , name , trait_spec , value ):
877+ if ((name == 'output_image' ) and
878+ (self .inputs .save_noise or isdefined (self .inputs .noise_image ))):
879+ noise_image = self ._gen_filename ('noise_image' )
880+ output = self ._gen_filename ('output_image' )
881+ newval = '[ %s, %s ]' % (output , noise_image )
882+ return trait_spec .argstr % newval
883+
884+ return super (DenoiseImage ,
885+ self )._format_arg (name , trait_spec , value )
886+
887+ def _parse_inputs (self , skip = None ):
888+ if skip is None :
889+ skip = []
890+ skip += ['save_noise' , 'noise_image' ]
891+ return super (DenoiseImage , self )._parse_inputs (skip = skip )
864892
865893 def _list_outputs (self ):
866894 outputs = self ._outputs ().get ()
867- outputs ['output_corrected_image' ] = os .path .abspath (self .inputs .output_image [0 ])
868- if len (self .inputs .output_image ) == 2 :
869- outputs ['output_noise_image' ] = os .path .abspath (self .inputs .output_image [1 ])
895+ outputs ['output_image' ] = os .path .abspath (
896+ self ._gen_filename ('output_image' ))
897+
898+ if self .inputs .save_noise or isdefined (self .inputs .noise_image ):
899+ outputs ['noise_image' ] = os .path .abspath (
900+ self ._gen_filename ('noise_image' ))
870901 return outputs
0 commit comments