Skip to content

Commit 14cf453

Browse files
author
Alexander Schaefer
committed
makes dilation optional (Boolean) so you dont lose time for dilation if you not need it
1 parent 6e60124 commit 14cf453

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

nipype/interfaces/cmtk/parcellation.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def create_annot_label(subject_id, subjects_dir, fs_dir, parcellation_name):
129129

130130
iflogger.info("[ DONE ]")
131131

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):
133133
""" Creates the ROI_%s.nii.gz files using the given parcellation information
134134
from networks. Iteratively create volume. """
135135
iflogger.info("Create the ROIs:")
@@ -231,28 +231,29 @@ def create_roi(subject_id, subjects_dir, fs_dir, parcellation_name):
231231

232232
iflogger.info("[ DONE ]")
233233
# 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 ]")
256257

257258

258259
def create_wm_mask(subject_id, subjects_dir, fs_dir, parcellation_name):
@@ -456,6 +457,7 @@ class ParcellateInputSpec(BaseInterfaceInputSpec):
456457
freesurfer_dir = Directory(exists=True, desc='Freesurfer main directory')
457458
subjects_dir = Directory(exists=True, desc='Freesurfer subjects directory')
458459
out_roi_file = File(genfile = True, desc='Region of Interest file for connectivity mapping')
460+
dilation = traits.Bool(False, usedefault=True)
459461

460462
class ParcellateOutputSpec(TraitedSpec):
461463
roi_file = File(exists=True, desc='Region of Interest file for connectivity mapping')
@@ -487,6 +489,7 @@ class Parcellate(BaseInterface):
487489
>>> parcellate.inputs.freesurfer_dir = '.'
488490
>>> parcellate.inputs.subjects_dir = '.'
489491
>>> parcellate.inputs.subject_id = 'subj1'
492+
>>> parcellate.inputs.dilation = True
490493
>>> parcellate.inputs.parcellation_name = 'scale500'
491494
>>> parcellate.run() # doctest: +SKIP
492495
"""
@@ -503,7 +506,7 @@ def _run_interface(self, runtime):
503506
iflogger.info("ROI_HR_th.nii.gz / fsmask_1mm.nii.gz CREATION")
504507
iflogger.info("=============================================")
505508
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)
507510
create_wm_mask(self.inputs.subject_id, self.inputs.subjects_dir, self.inputs.freesurfer_dir, self.inputs.parcellation_name)
508511
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)
509512
return runtime

0 commit comments

Comments
 (0)