@@ -225,8 +225,7 @@ def _get_ants_args(self):
225225 # Use this as the moving mask.
226226 args ['moving_image_mask' ] = create_cfm (
227227 self .inputs .moving_mask ,
228- "moving_cfm.nii.gz" ,
229- self .inputs .lesion_mask ,
228+ lesion_mask = self .inputs .lesion_mask ,
230229 global_mask = self .inputs .explicit_masking )
231230
232231 # If no moving mask is provided...
@@ -236,8 +235,7 @@ def _get_ants_args(self):
236235 # Use this as the moving mask.
237236 args ['moving_image_mask' ] = create_cfm (
238237 self .inputs .moving_image ,
239- "moving_cfm.nii.gz" ,
240- self .inputs .lesion_mask ,
238+ lesion_mask = self .inputs .lesion_mask ,
241239 global_mask = True )
242240
243241 """
@@ -265,7 +263,6 @@ def _get_ants_args(self):
265263 # Use this as the fixed mask.
266264 args ['fixed_image_mask' ] = create_cfm (
267265 self .inputs .reference_mask ,
268- "fixed_cfm.nii.gz" ,
269266 lesion_mask = None ,
270267 global_mask = True )
271268
@@ -283,7 +280,6 @@ def _get_ants_args(self):
283280 # Use this as the fixed mask
284281 args ['fixed_image_mask' ] = create_cfm (
285282 self .inputs .reference_image ,
286- "fixed_cfm.nii.gz" ,
287283 lesion_mask = None ,
288284 global_mask = True )
289285
@@ -314,7 +310,6 @@ def _get_ants_args(self):
314310 # Use this as the fixed mask.
315311 args ['fixed_image_mask' ] = create_cfm (
316312 op .join (mni_template , '%dmm_brainmask.nii.gz' % resolution ),
317- "fixed_cfm.nii.gz" ,
318313 lesion_mask = None ,
319314 global_mask = True )
320315
@@ -396,7 +391,7 @@ def mask(in_file, mask_file, new_name):
396391 return os .path .abspath (new_name )
397392
398393
399- def create_cfm (in_file , out_path , lesion_mask , global_mask = True ):
394+ def create_cfm (in_file , lesion_mask = None , global_mask = True , out_path = None ):
400395 """
401396 Create a mask to constrain registration.
402397
@@ -425,6 +420,12 @@ def create_cfm(in_file, out_path, lesion_mask, global_mask=True):
425420 import os
426421 import numpy as np
427422 import nibabel as nb
423+ from nipype .utils .filemanip import fname_presuffix
424+
425+ if out_path is None :
426+ out_path = fname_presuffix (in_file , suffix = '_cfm' , newpath = os .getcwd ())
427+ else :
428+ out_path = os .path .abspath (out_path )
428429
429430 # Load the input image
430431 in_img = nb .load (in_file )
@@ -458,7 +459,7 @@ def create_cfm(in_file, out_path, lesion_mask, global_mask=True):
458459 cfm_img .set_data_dtype (np .uint8 )
459460 cfm_img .to_filename (out_path )
460461
461- return os . path . abspath ( out_path )
462+ return out_path
462463
463464
464465def _write_outputs (runtime , out_fname = None ):
0 commit comments