def discrete_to_roi_features(self, fid, method='average'): """ Compute an ROI-level feature given the discrete features Parameters ---------- fid(string) the discrete feature under consideration method='average' the assessment method Results ------ the computed roi-feature is returned """ if method not in['min','max','average','cumulated_average']: raise ValueError, 'unknown method' if method=='cumulated_average': df = self.discrete_features[fid] data = self.discrete_features[fid] d0 = data[0] if np.size(d0) == np.shape(d0)[0]: np.reshape(d0,(np.size(d0),1)) fdim = d0.shape[1] ldata = np.zeros((self.k,fdim)) for k in range(self.k): dk = self.get_descendents(k) card = np.sum(self.get_size()[dk]) for ch in dk: ldata[k] += np.sum(data[ch],0) ldata[k]/=card self.set_roi_feature(fid,ldata) else: ldata = MultipleROI.discrete_to_roi_features(self, fid, method) return ldata
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], position[1], position[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', InputImage) 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',InputImage) 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" %\