def clean(self, valid): """ remove the rois for which valid==0 and update the hierarchy accordingly In case sum(valid)==0, 0 is returned """ if np.sum(valid)==0: return None # fixme: is None a correct way of dealing with k=0 ? # first clean as a forest sf = self.subforest(valid) Forest.__init__(self, sf.V, sf.parents) # then clean as a multiple ROI MultipleROI.clean(self, valid) return self.V
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()