@@ -378,16 +378,17 @@ class N4BiasFieldCorrection(ANTSCommand):
378
378
>>> n4_4.inputs.input_image = 'structural.nii'
379
379
>>> n4_4.inputs.save_bias = True
380
380
>>> n4_4.inputs.dimension = 3
381
- >>> n4_4.cmdline # doctest: +ELLIPSIS
381
+ >>> n4_4.cmdline
382
382
'N4BiasFieldCorrection -d 3 --input-image structural.nii \
383
- --output [ structural_corrected.nii, ... structural_bias.nii ]'
383
+ --output [ structural_corrected.nii, structural_bias.nii ]'
384
384
"""
385
385
386
386
_cmd = 'N4BiasFieldCorrection'
387
387
input_spec = N4BiasFieldCorrectionInputSpec
388
388
output_spec = N4BiasFieldCorrectionOutputSpec
389
389
390
390
def __init__ (self , * args , ** kwargs ):
391
+ """Instantiate the N4BiasFieldCorrection interface."""
391
392
self ._out_bias_file = None
392
393
super (N4BiasFieldCorrection , self ).__init__ (* args , ** kwargs )
393
394
@@ -424,32 +425,28 @@ def _parse_inputs(self, skip=None):
424
425
if not isdefined (bias_image ):
425
426
bias_image = fname_presuffix (os .path .basename (self .inputs .input_image ),
426
427
suffix = '_bias' )
427
- self ._out_bias_file = os . path . abspath ( bias_image )
428
+ self ._out_bias_file = bias_image
428
429
return super (N4BiasFieldCorrection , self )._parse_inputs (skip = skip )
429
430
430
431
def _list_outputs (self ):
431
432
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 )
439
433
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' ])
444
437
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
446
443
447
444
def _copy_header (self , fname ):
448
445
"""Copy header from input image to an output image."""
449
446
import nibabel as nb
450
447
in_img = nb .load (self .inputs .input_image )
451
448
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 ,
453
450
in_img .header )
454
451
new_img .set_data_dtype (out_img .get_data_dtype ())
455
452
new_img .to_filename (fname )
0 commit comments