algorithm/surf_tools.py
def make_mpm(pm, threshold, keep_prob = False, consider_baseline = False):
    """
    Make maximum probablistic map (mpm)
    
    Parameters:
    -----------
    pm: probabilistic map
        Note that pm.shape[3] should correspond to specific label of region
    threshold: threshold to filter vertex with low probability
    keep_prob: whether to keep maximum probability but not transform it into labels
               If True, return map with maximum probability
               If False, return map with label from maxmum probability
    consider_baseline: whether consider baseline or not when compute mpm
                       if True, check vertices that contain several probabilities, if p1+p2+...+pn < 0.5, then discard it
                       Details see Liang Wang, et al., Probabilistic Maps of Visual Topology in Human Cortex, 2015
    
    Return:
    -------
    mpm: maximum probabilistic map
    
    Example:
    >>> mpm = make_mpm(pm, 0.2)
    """
    if (pm.ndim != 4)&(pm.ndim != 2):
        raise Exception('Probablistic map should be 2/4 dimension to get maximum probablistic map')
    if pm.ndim == 4:
        pm = pm.reshape(pm.shape[0], pm.shape[3])
    pm[np.isnan(pm)] = 0
    pm_temp = np.zeros((pm.shape[0], pm.shape[1]+1))
    pm_temp[:, range(1,pm.shape[1]+1)] = pm
    pm_temp[pm_temp<threshold] = 0
    if consider_baseline is True:
        vex_discard = [(np.count_nonzero(pm_temp[i,:])>1)&((np.sum(pm_temp[i,:]))<0.5) for i in range(pm_temp.shape[0])]
        vex_disind = [i for i,e in enumerate(vex_discard) if e]
        pm_temp[vex_disind,:] = 0
    if not keep_prob: 
        mpm = np.argmax(pm_temp, axis=1)
    else:
        mpm = np.max(pm_temp, axis=1)
    mpm = mpm.reshape((-1, pm.ndim))
    return mpm

    Make maximum probablistic map (mpm)
    
    Parameters:
    -----------
    pm: probabilistic map
        Note that pm.shape[3] should correspond to specific label of region
    threshold: threshold to filter vertex with low probability
    keep_prob: whether to keep maximum probability but not transform it into labels
               If True, return map with maximum probability
               If False, return map with label from maxmum probability
    consider_baseline: whether consider baseline or not when compute mpm
                       if True, check vertices that contain several probabilities, if p1+p2+...+pn < 0.5, then discard it
                       Details see Liang Wang, et al., Probabilistic Maps of Visual Topology in Human Cortex, 2015
    
    Return:
    -------
    mpm: maximum probabilistic map
    
    Example:
    >>> mpm = make_mpm(pm, 0.2)
    
Make maximum probablistic map (mpm)
Parameters.

probabilistic map
Note that pm.shape[3] should correspond to specific label of region
threshold: threshold to filter vertex with low probability
keep_prob: whether to keep maximum probability but not transform it into labels
If True, return map with maximum probability
If False, return map with label from maxmum probability
consider_baseline: whether consider baseline or not when compute mpm
if True, check vertices that contain several probabilities, if p1+p2+...+pn < 0.5, then discard it
Details see Liang Wang, et al., Probabilistic Maps of Visual Topology in Human Cortex, 2015



maximum probabilistic map


Make maximum probablistic map ( mpm ) Parameters . probabilistic map Note that pm . shape [ 3 ] should correspond to specific label of region threshold : threshold to filter vertex with low probability keep_prob : whether to keep maximum probability but not transform it into labels If True return map with maximum probability If False return map with label from maxmum probability consider_baseline : whether consider baseline or not when compute mpm if True check vertices that contain several probabilities if p1 + p2 + ... + pn < 0 . 5 then discard it Details see Liang Wang et al . Probabilistic Maps of Visual Topology in Human Cortex 2015 maximum probabilistic map
def make_mpm(pm, threshold, keep_prob = False, consider_baseline = False):
    if (pm.ndim != 4)&(pm.ndim != 2):
        raise Exception('Probablistic map should be 2/4 dimension to get maximum probablistic map')
    if pm.ndim == 4:
        pm = pm.reshape(pm.shape[0], pm.shape[3])
    pm[np.isnan(pm)] = 0
    pm_temp = np.zeros((pm.shape[0], pm.shape[1]+1))
    pm_temp[:, range(1,pm.shape[1]+1)] = pm
    pm_temp[pm_temp<threshold] = 0
    if consider_baseline is True:
        vex_discard = [(np.count_nonzero(pm_temp[i,:])>1)&((np.sum(pm_temp[i,:]))<0.5) for i in range(pm_temp.shape[0])]
        vex_disind = [i for i,e in enumerate(vex_discard) if e]
        pm_temp[vex_disind,:] = 0
    if not keep_prob: 
        mpm = np.argmax(pm_temp, axis=1)
    else:
        mpm = np.max(pm_temp, axis=1)
    mpm = mpm.reshape((-1, pm.ndim))
    return mpm
def make_mpm ( pm , threshold , keep_prob = False , consider_baseline = False ) : if ( pm . ndim != 4 ) & ( pm . ndim != 2 ) : raise Exception ( 'Probablistic map should be 2/4 dimension to get maximum probablistic map' ) if pm . ndim == 4 : pm = pm . reshape ( pm . shape [ 0 ] , pm . shape [ 3 ] ) pm [ np . isnan ( pm ) ] = 0 pm_temp = np . zeros ( ( pm . shape [ 0 ] , pm . shape [ 1 ] + 1 ) ) pm_temp [ : , range ( 1 , pm . shape [ 1 ] + 1 ) ] = pm pm_temp [ pm_temp < threshold ] = 0 if consider_baseline is True : vex_discard = [ ( np . count_nonzero ( pm_temp [ i , : ] ) > 1 ) & ( ( np . sum ( pm_temp [ i , : ] ) ) < 0.5 ) for i in range ( pm_temp . shape [ 0 ] ) ] vex_disind = [ i for i , e in enumerate ( vex_discard ) if e ] pm_temp [ vex_disind , : ] = 0 if not keep_prob : mpm = np . argmax ( pm_temp , axis = 1 ) else : mpm = np . max ( pm_temp , axis = 1 ) mpm = mpm . reshape ( ( - 1 , pm . ndim ) ) return mpm
Make maximum probablistic map (mpm)
Parameters:
Make maximum probablistic map ( mpm ) Parameters :
"""
    Make maximum probablistic map (mpm)
    
    Parameters:
    -----------
    pm: probabilistic map
        Note that pm.shape[3] should correspond to specific label of region
    threshold: threshold to filter vertex with low probability
    keep_prob: whether to keep maximum probability but not transform it into labels
               If True, return map with maximum probability
               If False, return map with label from maxmum probability
    consider_baseline: whether consider baseline or not when compute mpm
                       if True, check vertices that contain several probabilities, if p1+p2+...+pn < 0.5, then discard it
                       Details see Liang Wang, et al., Probabilistic Maps of Visual Topology in Human Cortex, 2015
    
    Return:
    -------
    mpm: maximum probabilistic map
    
    Example:
    >>> mpm = make_mpm(pm, 0.2)
    """
pm
threshold
keep_prob
consider_baseline