def test_mroi2(verbose=0): nim = load(RefImage) mroi = MultipleROI(affine=nim.get_affine(), shape=nim.get_shape()) pos = 1.0*np.array([[10,10,10],[0,0,0],[20,0,20],[0,0,35]]) rad = np.array([5.,6.,7.,8.0]) mroi.as_multiple_balls(pos,rad) mroi.append_balls(np.array([[-10.,0.,10.]]),np.array([7.0])) mroi.set_roi_feature_from_image('T1_signal',RefImage) avt1 = mroi.get_roi_feature('T1_signal') assert(np.size(avt1)==5)
roiPath3 = os.path.join(swd, "blob_closest_to_%d_%d_%d.nii")%\ (position[0][0], position[0][1], position[0][2]) roi.from_position_and_image(blobPath, np.array(position)) roi.make_image(roiPath3) # --- 2.d make a set of ROIs from all the blobs mroi = MultipleROI( affine=affine, shape=shape) mroi.from_labelled_image(blobPath) roiPath4 = os.path.join(swd, "roi_all_blobs.nii") mroi.make_image(roiPath4) mroi.set_discrete_feature_from_image('activ', input_image) mroi.discrete_to_roi_features('activ') mroi.plot_roi_feature('activ') # ---- 2.e the same, a bit more complex mroi = MultipleROI( affine=affine, shape=shape) mroi.as_multiple_balls(np.array([[-10.,0.,10.]]),np.array([7.0])) mroi.from_labelled_image(blobPath,np.arange(1,20)) mroi.from_labelled_image(blobPath,np.arange(31,50)) roiPath5 = os.path.join(swd,"roi_some_blobs.nii") mroi.set_discrete_feature_from_image('activ',input_image) mroi.discrete_to_roi_features('activ') valid = mroi.get_roi_feature('activ')>4.0 mroi.clean(valid) mroi.make_image(roiPath5) print "Wrote ROI mask images in %s, \n %s \n %s \n and %s" %\ (roiPath2, roiPath3, roiPath4, roiPath5) mp.show()
mroi.set_discrete_feature_from_image('signal', image=fmri_data) # ROI average time courses mroi.discrete_to_roi_features('signal') # roi-level contrast average mroi.set_discrete_feature_from_image('contrast', image=contrast_image) mroi.discrete_to_roi_features('contrast') ######################################## # GLM analysis on the ROI average time courses ######################################## nreg = len(names) ROI_tc = mroi.get_roi_feature('signal') glm.fit(ROI_tc.T, X, method=method, model=model) mp.figure() mp.subplot(1, 2, 1) b1 = mp.bar(np.arange(nreg-1), glm.beta[:-1,0], width=.4, color='blue', label='r1') b2 = mp.bar(np.arange(nreg-1)+0.3, glm.beta[:-1,1], width=.4, color='red', label='r2') mp.xticks(np.arange(nreg-1), names[:-1]) mp.legend() mp.title('parameters estimates for the roi time courses') bx = mp.subplot(1, 2 ,2) mroi.plot_discrete_feature('contrast', bx)