@@ -357,6 +357,53 @@ def _gen_filename(self, name):
357
357
return None
358
358
359
359
360
+ class ApplyMaskInputSpec (FSTraitedSpec ):
361
+
362
+ in_file = File (exists = True ,mandatory = True ,position = - 3 ,argstr = "%s" ,
363
+ desc = "input image (will be masked)" )
364
+ mask_file = File (exists = True ,mandatory = True ,position = - 2 ,argstr = "%s" ,
365
+ desc = "image defining mask space" )
366
+ out_file = File (genfile = True ,position = - 1 ,argstr = "%s" ,
367
+ desc = "final image to write" )
368
+ xfm_file = File (exists = True ,argstr = "-xform %s" ,
369
+ desc = "LTA-format transformation matrix to align mask with input" )
370
+ invert_xfm = traits .Bool (argstr = "-invert" ,desc = "invert transformation" )
371
+ xfm_source = File (exists = True ,argstr = "-lta_src %s" ,desc = "image defining transform source space" )
372
+ xfm_target = File (exists = True ,argstr = "-lta_dst %s" ,desc = "image defining transform target space" )
373
+ use_abs = traits .Bool (argstr = "-abs" ,desc = "take absolute value of mask before applying" )
374
+ mask_thresh = traits .Float (argstr = "-T %.4f" ,desc = "threshold mask before applying" )
375
+
376
+ class ApplyMaskOutputSpec (TraitedSpec ):
377
+
378
+ out_file = File (exists = True ,desc = "masked image" )
379
+
380
+ class ApplyMask (FSCommand ):
381
+ """Use Freesurfer's mri_mask to apply a mask to an image.
382
+
383
+ The mask file need not be binarized; it can be thresholded above a given
384
+ value before application. It can also optionally be transformed into input
385
+ space with an LTA matrix.
386
+
387
+ """
388
+ _cmd = "mri_mask"
389
+ input_spec = ApplyMaskInputSpec
390
+ output_spec = ApplyMaskOutputSpec
391
+
392
+ def _list_outputs (self ):
393
+ outputs = self ._outputs ().get ()
394
+ outputs ["out_file" ] = self .inputs .out_file
395
+ if not isdefined (outputs ["out_file" ]):
396
+ outputs ["out_file" ] = fname_presuffix (self .inputs .in_file ,
397
+ suffix = "_masked" ,
398
+ newpath = os .getcwd (),
399
+ use_ext = True )
400
+ return outputs
401
+
402
+ def _gen_filename (self , name ):
403
+ if name == "out_file" :
404
+ return self ._list_outputs ()[name ]
405
+ return None
406
+
360
407
class SurfaceSnapshotsInputSpec (FSTraitedSpec ):
361
408
362
409
subject_id = traits .String (position = 1 ,argstr = "%s" ,mandatory = True ,
0 commit comments