@@ -129,7 +129,7 @@ def create_annot_label(subject_id, subjects_dir, fs_dir, parcellation_name):
129
129
130
130
iflogger .info ("[ DONE ]" )
131
131
132
- def create_roi (subject_id , subjects_dir , fs_dir , parcellation_name ):
132
+ def create_roi (subject_id , subjects_dir , fs_dir , parcellation_name , dilation ):
133
133
""" Creates the ROI_%s.nii.gz files using the given parcellation information
134
134
from networks. Iteratively create volume. """
135
135
iflogger .info ("Create the ROIs:" )
@@ -231,28 +231,29 @@ def create_roi(subject_id, subjects_dir, fs_dir, parcellation_name):
231
231
232
232
iflogger .info ("[ DONE ]" )
233
233
# dilate cortical regions
234
- iflogger .info ("Dilating cortical regions..." )
235
- # loop throughout all the voxels belonging to the aseg GM volume
236
- for j in range (xx .size ):
237
- if rois [xx [j ],yy [j ],zz [j ]] == 0 :
238
- local = extract (rois , shape , position = (xx [j ],yy [j ],zz [j ]), fill = 0 )
239
- mask = local .copy ()
240
- mask [np .nonzero (local > 0 )] = 1
241
- thisdist = np .multiply (dist ,mask )
242
- thisdist [np .nonzero (thisdist == 0 )] = np .amax (thisdist )
243
- value = np .int_ (local [np .nonzero (thisdist == np .amin (thisdist ))])
244
- if value .size > 1 :
245
- counts = np .bincount (value )
246
- value = np .argmax (counts )
247
- rois [xx [j ],yy [j ],zz [j ]] = value
248
-
249
- # store volume eg in ROIv_scale33.nii.gz
250
- out_roi = op .join (output_dir , 'ROIv_%s.nii.gz' % parcellation_name )
251
- iflogger .info ("Save output image to %s" % out_roi )
252
- img = nb .Nifti1Image (rois , aseg .get_affine (), hdr2 )
253
- nb .save (img , out_roi )
254
-
255
- iflogger .info ("[ DONE ]" )
234
+ if (dilation == True ) :
235
+ iflogger .info ("Dilating cortical regions..." )
236
+ # loop throughout all the voxels belonging to the aseg GM volume
237
+ for j in range (xx .size ):
238
+ if rois [xx [j ],yy [j ],zz [j ]] == 0 :
239
+ local = extract (rois , shape , position = (xx [j ],yy [j ],zz [j ]), fill = 0 )
240
+ mask = local .copy ()
241
+ mask [np .nonzero (local > 0 )] = 1
242
+ thisdist = np .multiply (dist ,mask )
243
+ thisdist [np .nonzero (thisdist == 0 )] = np .amax (thisdist )
244
+ value = np .int_ (local [np .nonzero (thisdist == np .amin (thisdist ))])
245
+ if value .size > 1 :
246
+ counts = np .bincount (value )
247
+ value = np .argmax (counts )
248
+ rois [xx [j ],yy [j ],zz [j ]] = value
249
+
250
+ # store volume eg in ROIv_scale33.nii.gz
251
+ out_roi = op .join (output_dir , 'ROIv_%s.nii.gz' % parcellation_name )
252
+ iflogger .info ("Save output image to %s" % out_roi )
253
+ img = nb .Nifti1Image (rois , aseg .get_affine (), hdr2 )
254
+ nb .save (img , out_roi )
255
+
256
+ iflogger .info ("[ DONE ]" )
256
257
257
258
258
259
def create_wm_mask (subject_id , subjects_dir , fs_dir , parcellation_name ):
@@ -456,6 +457,7 @@ class ParcellateInputSpec(BaseInterfaceInputSpec):
456
457
freesurfer_dir = Directory (exists = True , desc = 'Freesurfer main directory' )
457
458
subjects_dir = Directory (exists = True , desc = 'Freesurfer subjects directory' )
458
459
out_roi_file = File (genfile = True , desc = 'Region of Interest file for connectivity mapping' )
460
+ dilation = traits .Bool (False , usedefault = True )
459
461
460
462
class ParcellateOutputSpec (TraitedSpec ):
461
463
roi_file = File (exists = True , desc = 'Region of Interest file for connectivity mapping' )
@@ -487,6 +489,7 @@ class Parcellate(BaseInterface):
487
489
>>> parcellate.inputs.freesurfer_dir = '.'
488
490
>>> parcellate.inputs.subjects_dir = '.'
489
491
>>> parcellate.inputs.subject_id = 'subj1'
492
+ >>> parcellate.inputs.dilation = True
490
493
>>> parcellate.inputs.parcellation_name = 'scale500'
491
494
>>> parcellate.run() # doctest: +SKIP
492
495
"""
@@ -503,7 +506,7 @@ def _run_interface(self, runtime):
503
506
iflogger .info ("ROI_HR_th.nii.gz / fsmask_1mm.nii.gz CREATION" )
504
507
iflogger .info ("=============================================" )
505
508
create_annot_label (self .inputs .subject_id , self .inputs .subjects_dir , self .inputs .freesurfer_dir , self .inputs .parcellation_name )
506
- create_roi (self .inputs .subject_id , self .inputs .subjects_dir , self .inputs .freesurfer_dir , self .inputs .parcellation_name )
509
+ create_roi (self .inputs .subject_id , self .inputs .subjects_dir , self .inputs .freesurfer_dir , self .inputs .parcellation_name , self . inputs . dilation )
507
510
create_wm_mask (self .inputs .subject_id , self .inputs .subjects_dir , self .inputs .freesurfer_dir , self .inputs .parcellation_name )
508
511
crop_and_move_datasets (self .inputs .subject_id , self .inputs .subjects_dir , self .inputs .freesurfer_dir , self .inputs .parcellation_name , self .inputs .out_roi_file )
509
512
return runtime
0 commit comments