algorithm/surf_tools.py
def leave1out_location_overlap(imgdata1, imgdata2, labels, labelnum = None, index = 'dice', thr_meth = 'prob', prob_meth = 'part', thr_range = [0,1,0.1], controlsize = False, actdata = None):
    """
    A leave one out cross validation method for threshold to best overlapping in probabilistic map
    
    Parameters:
    -----------
    imgdata1: A 2/4 dimensional data, used as train data
    imgdata2: A 2/4 dimensional data, used as test data
    labels: list, label number used to extract dice coefficient
    labelnum: by default is None, label number size. We recommend to provide label number here.
    index: 'dice' or 'percent'
    thr_meth: 'prob', threshold probabilistic map by probabilistic values (MPM)
              'number', threshold probabilistic map by numbers of vertex
    prob_meth: 'all' or 'part' subjects to use to compute probablistic map
    thr_range: pre-set threshold range to find the best maximum probabilistic threshold
    controlsize: whether control label data size with template mpm label size or not, by default is False.
    actdata: if controlsize is True, please input actdata as a parameter. By default is None.

    Return:
    -------
    output_overlap: dice coefficient/percentage computed from function
                    outputdice consists of a 3 dimension array
                    subjects x threhold x regions
                    the first dimension means the values of each leave one out (leave one subject out)
                    the second dimension means the results of pre-set threshold
                    the third dimension means the results of each region

    Example:
    --------
    >>> output_overlap = leave1out_location_overlap(imgdata1, imgdata1, [2,4], labelnum = 4)
    """
    if imgdata1.ndim == 4:
        imgdata1 = imgdata1.reshape(imgdata1.shape[0], imgdata1.shape[-1])
    if imgdata2.ndim == 4:
        imgdata2 = imgdata2.reshape(imgdata2.shape[0], imgdata2.shape[-1])

    assert imgdata1.shape == imgdata2.shape, "The shape of imgdata1 and imgdata2 must be equal."
    
    if actdata is not None:
        if actdata.ndim == 4:
            actdata = actdata.reshape(actdata.shape[0], actdata.shape[-1])
    output_overlap = []
    for i in range(imgdata1.shape[-1]):
        data_temp = np.delete(imgdata1, i, axis=1)
        testdata = np.expand_dims(imgdata2[:,i],axis=1)
        if actdata is not None:
            test_actdata = np.expand_dims(actdata[:,i],axis=1)
        else:
            test_actdata = None
        pm = make_pm(data_temp, prob_meth, labelnum)
        pm_temp = cv_pm_overlap(pm, testdata, labels, labels, thr_meth = thr_meth, thr_range = thr_range, index = index, cmpalllbl = False, controlsize = controlsize, actdata = test_actdata)
        output_overlap.append(pm_temp)
    output_array = np.array(output_overlap)
    return output_array.reshape(output_array.shape[0], output_array.shape[2], output_array.shape[3])

    A leave one out cross validation method for threshold to best overlapping in probabilistic map
    
    Parameters:
    -----------
    imgdata1: A 2/4 dimensional data, used as train data
    imgdata2: A 2/4 dimensional data, used as test data
    labels: list, label number used to extract dice coefficient
    labelnum: by default is None, label number size. We recommend to provide label number here.
    index: 'dice' or 'percent'
    thr_meth: 'prob', threshold probabilistic map by probabilistic values (MPM)
              'number', threshold probabilistic map by numbers of vertex
    prob_meth: 'all' or 'part' subjects to use to compute probablistic map
    thr_range: pre-set threshold range to find the best maximum probabilistic threshold
    controlsize: whether control label data size with template mpm label size or not, by default is False.
    actdata: if controlsize is True, please input actdata as a parameter. By default is None.

    Return:
    -------
    output_overlap: dice coefficient/percentage computed from function
                    outputdice consists of a 3 dimension array
                    subjects x threhold x regions
                    the first dimension means the values of each leave one out (leave one subject out)
                    the second dimension means the results of pre-set threshold
                    the third dimension means the results of each region

    Example:
    --------
    >>> output_overlap = leave1out_location_overlap(imgdata1, imgdata1, [2,4], labelnum = 4)
    
A leave one out cross validation method for threshold to best overlapping in probabilistic map
Parameters.

A 2/4 dimensional data, used as train data
imgdata2: A 2/4 dimensional data, used as test data
labels: list, label number used to extract dice coefficient
labelnum: by default is None, label number size. We recommend to provide label number here.



dice coefficient/percentage computed from function
outputdice consists of a 3 dimension array
subjects x threhold x regions
the first dimension means the values of each leave one out (leave one subject out)
the second dimension means the results of pre-set threshold
the third dimension means the results of each region



>>> output_overlap = leave1out_location_overlap(imgdata1, imgdata1, [2,4], labelnum = 4)
A leave one out cross validation method for threshold to best overlapping in probabilistic map Parameters . A 2 / 4 dimensional data used as train data imgdata2 : A 2 / 4 dimensional data used as test data labels : list label number used to extract dice coefficient labelnum : by default is None label number size . We recommend to provide label number here . dice coefficient / percentage computed from function outputdice consists of a 3 dimension array subjects x threhold x regions the first dimension means the values of each leave one out ( leave one subject out ) the second dimension means the results of pre - set threshold the third dimension means the results of each region >>> output_overlap = leave1out_location_overlap ( imgdata1 imgdata1 [ 2 4 ] labelnum = 4 )
def leave1out_location_overlap(imgdata1, imgdata2, labels, labelnum = None, index = 'dice', thr_meth = 'prob', prob_meth = 'part', thr_range = [0,1,0.1], controlsize = False, actdata = None):
    if imgdata1.ndim == 4:
        imgdata1 = imgdata1.reshape(imgdata1.shape[0], imgdata1.shape[-1])
    if imgdata2.ndim == 4:
        imgdata2 = imgdata2.reshape(imgdata2.shape[0], imgdata2.shape[-1])
    assert imgdata1.shape == imgdata2.shape, "The shape of imgdata1 and imgdata2 must be equal."
    if actdata is not None:
        if actdata.ndim == 4:
            actdata = actdata.reshape(actdata.shape[0], actdata.shape[-1])
    output_overlap = []
    for i in range(imgdata1.shape[-1]):
        data_temp = np.delete(imgdata1, i, axis=1)
        testdata = np.expand_dims(imgdata2[:,i],axis=1)
        if actdata is not None:
            test_actdata = np.expand_dims(actdata[:,i],axis=1)
        else:
            test_actdata = None
        pm = make_pm(data_temp, prob_meth, labelnum)
        pm_temp = cv_pm_overlap(pm, testdata, labels, labels, thr_meth = thr_meth, thr_range = thr_range, index = index, cmpalllbl = False, controlsize = controlsize, actdata = test_actdata)
        output_overlap.append(pm_temp)
    output_array = np.array(output_overlap)
    return output_array.reshape(output_array.shape[0], output_array.shape[2], output_array.shape[3])
def leave1out_location_overlap ( imgdata1 , imgdata2 , labels , labelnum = None , index = 'dice' , thr_meth = 'prob' , prob_meth = 'part' , thr_range = [ 0 , 1 , 0.1 ] , controlsize = False , actdata = None ) : if imgdata1 . ndim == 4 : imgdata1 = imgdata1 . reshape ( imgdata1 . shape [ 0 ] , imgdata1 . shape [ - 1 ] ) if imgdata2 . ndim == 4 : imgdata2 = imgdata2 . reshape ( imgdata2 . shape [ 0 ] , imgdata2 . shape [ - 1 ] ) assert imgdata1 . shape == imgdata2 . shape , "The shape of imgdata1 and imgdata2 must be equal." if actdata is not None : if actdata . ndim == 4 : actdata = actdata . reshape ( actdata . shape [ 0 ] , actdata . shape [ - 1 ] ) output_overlap = [ ] for i in range ( imgdata1 . shape [ - 1 ] ) : data_temp = np . delete ( imgdata1 , i , axis = 1 ) testdata = np . expand_dims ( imgdata2 [ : , i ] , axis = 1 ) if actdata is not None : test_actdata = np . expand_dims ( actdata [ : , i ] , axis = 1 ) else : test_actdata = None pm = make_pm ( data_temp , prob_meth , labelnum ) pm_temp = cv_pm_overlap ( pm , testdata , labels , labels , thr_meth = thr_meth , thr_range = thr_range , index = index , cmpalllbl = False , controlsize = controlsize , actdata = test_actdata ) output_overlap . append ( pm_temp ) output_array = np . array ( output_overlap ) return output_array . reshape ( output_array . shape [ 0 ] , output_array . shape [ 2 ] , output_array . shape [ 3 ] )
A leave one out cross validation method for threshold to best overlapping in probabilistic map
Parameters:
A leave one out cross validation method for threshold to best overlapping in probabilistic map Parameters :
"""
    A leave one out cross validation method for threshold to best overlapping in probabilistic map
    
    Parameters:
    -----------
    imgdata1: A 2/4 dimensional data, used as train data
    imgdata2: A 2/4 dimensional data, used as test data
    labels: list, label number used to extract dice coefficient
    labelnum: by default is None, label number size. We recommend to provide label number here.
    index: 'dice' or 'percent'
    thr_meth: 'prob', threshold probabilistic map by probabilistic values (MPM)
              'number', threshold probabilistic map by numbers of vertex
    prob_meth: 'all' or 'part' subjects to use to compute probablistic map
    thr_range: pre-set threshold range to find the best maximum probabilistic threshold
    controlsize: whether control label data size with template mpm label size or not, by default is False.
    actdata: if controlsize is True, please input actdata as a parameter. By default is None.

    Return:
    -------
    output_overlap: dice coefficient/percentage computed from function
                    outputdice consists of a 3 dimension array
                    subjects x threhold x regions
                    the first dimension means the values of each leave one out (leave one subject out)
                    the second dimension means the results of pre-set threshold
                    the third dimension means the results of each region

    Example:
    --------
    >>> output_overlap = leave1out_location_overlap(imgdata1, imgdata1, [2,4], labelnum = 4)
    """
imgdata1
imgdata2
labels
labelnum
index
thr_meth
prob_meth
thr_range
controlsize
actdata