drift_model='cosine', hfcut=128, hrf_model=hrf_model, add_regs=motion, add_reg_names=add_reg_names) ######################################## # Create ROIs ######################################## positions = np.array([[60, -30, 5], [50, 27, 5]]) # in mm (here in the MNI space) radii = np.array([8, 6]) domain = grid_domain_from_image(mask) my_roi = mroi.subdomain_from_balls(domain, positions, radii) # to save an image of the ROIs save(my_roi.to_image(), path.join(write_dir, "roi.nii")) ####################################### # Get the FMRI data ####################################### fmri_data = surrogate_4d_dataset(mask=mask, dmtx=X)[0] Y = fmri_data.get_data()[mask_array] # artificially added signal in ROIs to make the example more meaningful activation = 30 * (X.T[1] + .5 * X.T[0]) for (position, radius) in zip(positions, radii): Y[((domain.coord - position)**2).sum(1) < radius**2 + 1] += activation
# compute the constrast image related to it zvals = glm.contrast(contrast).z_score() zmap = mask_array.astype(np.float) zmap[mask_array] = zvals ######################################## # Create ROIs ######################################## positions = np.array([[60, -30, 5], [50, 27, 5]]) # in mm (here in the MNI space) radii = np.array([8, 6]) domain = grid_domain_from_image(mask) my_roi = mroi.subdomain_from_balls(domain, positions, radii) # to save an image of the ROIs save(my_roi.to_image(), op.join(write_dir, "roi.nii")) # exact the time courses with ROIs thresholded_fmri = fmri_data.get_data()[mask_array] signal_feature = [thresholded_fmri[my_roi.select_id(id, roi=False)] for id in my_roi.get_id()] my_roi.set_feature('signal', signal_feature) # ROI average time courses my_roi.set_roi_feature('signal_avg', my_roi.representative_feature('signal')) # roi-level contrast average thresholded_contrast = zvals
# paths data_dir = os.path.expanduser(os.path.join('~', '.nipy', 'tests', 'data')) input_image = os.path.join(data_dir,'spmT_0029.nii.gz') mask_image = os.path.join(data_dir,'mask.nii.gz') #get_data_light.get_it() # write dir swd = tempfile.mkdtemp() # ----------------------------------------------------- # example 1: create the ROI froma a given position # ----------------------------------------------------- position = np.array([[0, 0, 0]]) domain = grid_domain_from_image(mask_image) roi = mroi.subdomain_from_balls(domain, position, np.array([5.0])) roi_domain = domain.mask(roi.label>-1) roi_domain.to_image(os.path.join(swd, "myroi.nii")) print 'Wrote an ROI mask image in %s' %os.path.join(swd, "myroi.nii") # fixme: pot roi feature ... # ---------------------------------------------------- # ---- example 2: create ROIs from a blob image ------ # ---------------------------------------------------- # --- 2.a create the blob image # parameters threshold = 3.0 # blob-forming threshold smin = 5 # size threshold on bblobs
if (not path.exists(input_image)) or (not path.exists(mask_image)): get_second_level_dataset() # write directory write_dir = path.join(getcwd(), 'results') if not path.exists(write_dir): mkdir(write_dir) # ----------------------------------------------------- # example 1: create the ROI from a given position # ----------------------------------------------------- position = np.array([[0, 0, 0]]) domain = grid_domain_from_image(mask_image) roi = mroi.subdomain_from_balls(domain, position, np.array([5.0])) roi_domain = domain.mask(roi.label > -1) dom_img = roi_domain.to_image() save(dom_img, path.join(write_dir, "myroi.nii")) print('Wrote an ROI mask image in %s' % path.join(write_dir, "myroi.nii")) # ---------------------------------------------------- # ---- example 2: create ROIs from a blob image ------ # ---------------------------------------------------- # --- 2.a create the blob image # parameters threshold = 3.0 # blob-forming threshold smin = 10 # size threshold on bblobs