@@ -317,6 +317,29 @@ else:
317317 if args .num_threads and args .num_threads > 1 :
318318 labeler .inputs .num_threads = args .num_threads
319319
320+ def mask_labels (intensity_image , label_image , output_dir = None ):
321+ import nibabel as nb
322+ import os
323+ thick_data = nb .load (intensity_image ).get_data () > 0
324+ limg = nb .load (label_image )
325+ label_data = limg .get_data ()
326+ new_labels = thick_data * label_data * (label_data >= 1000 ) + \
327+ (label_data < 1000 ) * label_data
328+ new_label_img = nb .Nifti1Image (new_labels ,
329+ header = limg .header ,
330+ affine = limg .affine )
331+ new_label_file = os .path .join (os .getcwd (), 'newlabels.nii.gz' )
332+ new_label_img .to_filename (new_label_file )
333+ if output_dir is None :
334+ output_dir = os .path .dirname (intensity_image )
335+ limg .to_filename (os .path .join (output_dir , 'OASISlabels.nii.gz' ))
336+ return new_label_file
337+ masker = Node (Fn (function = mask_labels , input_names = ['intensity_image' ,
338+ 'label_image' ,
339+ 'output_dir' ],
340+ output_names = ['new_label_file' ]),
341+ name = 'masker' )
342+
320343 tocsv = Node (LabelGeometry (), name = 'get_measures' )
321344 tocsv .inputs .output_file = os .path .join (ants_output , ID ,
322345 'antslabelstats.csv' )
@@ -331,11 +354,14 @@ else:
331354 'mask_image' )
332355 mbFlow .connect (corticalthickness , 'CorticalThickness' ,
333356 tocsv , 'intensity_image' )
357+ mbFlow .connect (corticalthickness , 'CorticalThickness' ,
358+ masker , 'intensity_image' )
334359
335360 mbFlow .connect (transformer , 'output_image' , labeler , 'atlas_image' )
336361 mbFlow .connect (transformer_nn , 'output_image' , labeler ,
337362 'atlas_segmentation_image' )
338- mbFlow .connect (labeler , 'out_label_fusion' , tocsv , 'label_image' )
363+ mbFlow .connect (labeler , 'out_label_fusion' , masker , 'label_image' )
364+ mbFlow .connect (masker , 'new_label_file' , tocsv , 'label_image' )
339365
340366 # ----------------------------------------------------------------------------
341367 # Connect ants to Mindboggle
0 commit comments