def test_roi1(verbose=0): nim = load(RefImage) affine = nim.get_affine() shape = nim.get_shape() lroi = DiscreteROI("myroi", affine, shape) lroi.from_position(np.array([0,0,0]),5.0) roiPath = os.path.join(WriteDir,"myroi.nii") lroi.make_image(roiPath) assert(os.path.isfile(roiPath))
bmap[nroi.label==k] = average_activation[k] # saving the blob image,i. e. a label image wlabel = -2*np.ones(shape) wlabel[data!=0] = nroi.label blobPath = os.path.join(swd, "blob.nii") wim = Nifti1Image(wlabel, affine) wim.get_header()['descrip'] = 'blob image extracted from %s'%input_image save(wim, blobPath) # --- 2.b take blob labelled "1" as an ROI roi = DiscreteROI( affine=affine, shape=shape) roi.from_labelled_image(blobPath, 1) roiPath2 = os.path.join(swd, "roi_blob_1.nii") roi.make_image(roiPath2) # --- 2.c take the blob closest to 'position as an ROI' 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')
swd = tempfile.mkdtemp() data_dir = os.path.expanduser(os.path.join('~', '.nipy', 'tests', 'data')) InputImage = os.path.join(data_dir,'spmT_0029.nii.gz') MaskImage = os.path.join(data_dir,'mask.nii.gz') # ----------------------------------------------------- # example 1: create the ROI froma a given position # ----------------------------------------------------- position = [0,0,0] nim = load(MaskImage) affine = nim.get_affine() shape = nim.get_shape() roi = DiscreteROI("myroi", affine,shape) roi.from_position(np.array(position), 5.0) roi.make_image(os.path.join(swd,"myroi.nii")) roi.set_feature_from_image('activ',InputImage) roi.plot_feature('activ') print 'Wrote an ROI mask image in %s' %os.path.join(swd,"myroi.nii") # ---------------------------------------------------- # ---- example 2: create ROIs from a blob image ------ # ---------------------------------------------------- # --- 2.a create the blob image import nipy.neurospin.graph.field as ff import nipy.neurospin.spatial_models.hroi as hroi # parameters