@@ -378,16 +378,17 @@ class N4BiasFieldCorrection(ANTSCommand):
378378 >>> n4_4.inputs.input_image = 'structural.nii'
379379 >>> n4_4.inputs.save_bias = True
380380 >>> n4_4.inputs.dimension = 3
381- >>> n4_4.cmdline # doctest: +ELLIPSIS
381+ >>> n4_4.cmdline
382382 'N4BiasFieldCorrection -d 3 --input-image structural.nii \
383- --output [ structural_corrected.nii, ... structural_bias.nii ]'
383+ --output [ structural_corrected.nii, structural_bias.nii ]'
384384 """
385385
386386 _cmd = 'N4BiasFieldCorrection'
387387 input_spec = N4BiasFieldCorrectionInputSpec
388388 output_spec = N4BiasFieldCorrectionOutputSpec
389389
390390 def __init__ (self , * args , ** kwargs ):
391+ """Instantiate the N4BiasFieldCorrection interface."""
391392 self ._out_bias_file = None
392393 super (N4BiasFieldCorrection , self ).__init__ (* args , ** kwargs )
393394
@@ -424,32 +425,28 @@ def _parse_inputs(self, skip=None):
424425 if not isdefined (bias_image ):
425426 bias_image = fname_presuffix (os .path .basename (self .inputs .input_image ),
426427 suffix = '_bias' )
427- self ._out_bias_file = os . path . abspath ( bias_image )
428+ self ._out_bias_file = bias_image
428429 return super (N4BiasFieldCorrection , self )._parse_inputs (skip = skip )
429430
430431 def _list_outputs (self ):
431432 outputs = super (N4BiasFieldCorrection , self )._list_outputs ()
432- if self ._out_bias_file :
433- outputs ['bias_image' ] = self ._out_bias_file
434- return outputs
435-
436- def _run_interface (self , runtime , correct_return_codes = (0 , )):
437- runtime = super (N4BiasFieldCorrection , self )._run_interface (
438- runtime , correct_return_codes )
439433
440- if self .inputs .copy_header and runtime .returncode in correct_return_codes :
441- self ._copy_header (self .inputs .output_image )
442- if self ._out_bias_file :
443- self ._copy_header (self ._out_bias_file )
434+ # Fix headers
435+ if self .inputs .copy_header :
436+ self ._copy_header (outputs ['output_image' ])
444437
445- return runtime
438+ if self ._out_bias_file :
439+ outputs ['bias_image' ] = os .path .abspath (self ._out_bias_file )
440+ if self .inputs .copy_header :
441+ self ._copy_header (outputs ['bias_image' ])
442+ return outputs
446443
447444 def _copy_header (self , fname ):
448445 """Copy header from input image to an output image."""
449446 import nibabel as nb
450447 in_img = nb .load (self .inputs .input_image )
451448 out_img = nb .load (fname , mmap = False )
452- new_img = out_img .__class__ (out_img .get_data (), in_img .affine ,
449+ new_img = out_img .__class__ (out_img .get_fdata (), in_img .affine ,
453450 in_img .header )
454451 new_img .set_data_dtype (out_img .get_data_dtype ())
455452 new_img .to_filename (fname )
0 commit comments