示例#1
0
    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
示例#2
0
    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
示例#3
0
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)
示例#4
0
def test_mroi1(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]))
    roiPath = os.path.join(WriteDir,"mroi.nii")
    mroi.make_image(roiPath)
    assert(os.path.isfile(roiPath))
示例#5
0
 def __init__(self, parents=None, affine=np.eye(4), shape=None,
              xyz=None, id='nroi'):
     """
     Building the NROI
     
     Parameters
     ----------
     parents=None: array of shape(k) providing
                   the hierachical structure
                   if parent==None, None is returned
     affine=np.eye(4), array of shape(4,4),
                        coordinate-defining affine transformation
     shape=None, tuple of length 3 defining the size of the grid 
                 implicit to the discrete ROI definition
     xyz=None, list of arrays of shape (3, nvox)
              that yield the grid position of each grid guy.
     id='nroi', string, region identifier
     """
     if parents==None:
         return None
     k = np.size(parents)
     Forest.__init__(self,k,parents)
     MultipleROI.__init__(self,id, k, affine, shape, xyz)
示例#6
0
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], 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')