algorithm/surf_tools.py
def cutrg2parcels(orig_mask, faces, label = 1, label_rules = 'random'):
    """
    Use region growing method to cut discontinuous specific regions to parcels

    Parameters:
    -----------
    orig_mask: original mask has a/several small parcel(s) with labels
    faces: relationship of connection
    label[int]: specific label of orig_mask that used to cut into parcels
    label_ruls[string]: 'random', arrange new label randomly
                        'min2max', arrange new label from minimum vertex to maximum vertex
                        'max2min', arrange new label from maxmum vertex to minimum vertex

    Returns:
    --------
    parcel_mask: parcel mask that generated from specific label of orig_mask

    Example:
    --------
    >>> parcel_mask = cutrg2parcels(orig_mask, faces, 1)
    """
    if not isinstance(label, int):
        raise Exception('label need to be an int')
    lbl_orig_mask = tools.get_specificroi(orig_mask, label)
    parcel_mask = np.zeros_like(orig_mask)

    orig_maskset = set(np.where(lbl_orig_mask!=0)[0])
    connvex = set()
    dif_connvex = orig_maskset.difference(connvex)

    parcel_num = 0
    if label_rules == 'random':
        seedchoose = random.choice
    elif label_rules == 'min2max':
        seedchoose = np.min
    elif label_rules == 'max2min':
        seedchoose = np.max
    else:
        raise Exception('Set wrong parameter label_rules.')

    while len(dif_connvex) != 0:
        seedpt = seedchoose(tuple(dif_connvex))
        parcel_connvex = get_connvex(seedpt, faces, labelmask = lbl_orig_mask, label = label)
        connvex.update(parcel_connvex)
        dif_connvex = orig_maskset.difference(connvex)
        parcel_num += 1
        parcel_mask = tools.make_lblmask_by_loc(parcel_mask, tuple(parcel_connvex), parcel_num)
        print('parcel number: {0}'.format(parcel_num))
    return parcel_mask

    Use region growing method to cut discontinuous specific regions to parcels

    Parameters:
    -----------
    orig_mask: original mask has a/several small parcel(s) with labels
    faces: relationship of connection
    label[int]: specific label of orig_mask that used to cut into parcels
    label_ruls[string]: 'random', arrange new label randomly
                        'min2max', arrange new label from minimum vertex to maximum vertex
                        'max2min', arrange new label from maxmum vertex to minimum vertex

    Returns:
    --------
    parcel_mask: parcel mask that generated from specific label of orig_mask

    Example:
    --------
    >>> parcel_mask = cutrg2parcels(orig_mask, faces, 1)
    
Use region growing method to cut discontinuous specific regions to parcels
Parameters.





parcel mask that generated from specific label of orig_mask




Use region growing method to cut discontinuous specific regions to parcels Parameters . parcel mask that generated from specific label of orig_mask
def cutrg2parcels(orig_mask, faces, label = 1, label_rules = 'random'):
    if not isinstance(label, int):
        raise Exception('label need to be an int')
    lbl_orig_mask = tools.get_specificroi(orig_mask, label)
    parcel_mask = np.zeros_like(orig_mask)
    orig_maskset = set(np.where(lbl_orig_mask!=0)[0])
    connvex = set()
    dif_connvex = orig_maskset.difference(connvex)
    parcel_num = 0
    if label_rules == 'random':
        seedchoose = random.choice
    elif label_rules == 'min2max':
        seedchoose = np.min
    elif label_rules == 'max2min':
        seedchoose = np.max
    else:
        raise Exception('Set wrong parameter label_rules.')
    while len(dif_connvex) != 0:
        seedpt = seedchoose(tuple(dif_connvex))
        parcel_connvex = get_connvex(seedpt, faces, labelmask = lbl_orig_mask, label = label)
        connvex.update(parcel_connvex)
        dif_connvex = orig_maskset.difference(connvex)
        parcel_num += 1
        parcel_mask = tools.make_lblmask_by_loc(parcel_mask, tuple(parcel_connvex), parcel_num)
        print('parcel number: {0}'.format(parcel_num))
    return parcel_mask
def cutrg2parcels ( orig_mask , faces , label = 1 , label_rules = 'random' ) : if not isinstance ( label , int ) : raise Exception ( 'label need to be an int' ) lbl_orig_mask = tools . get_specificroi ( orig_mask , label ) parcel_mask = np . zeros_like ( orig_mask ) orig_maskset = set ( np . where ( lbl_orig_mask != 0 ) [ 0 ] ) connvex = set ( ) dif_connvex = orig_maskset . difference ( connvex ) parcel_num = 0 if label_rules == 'random' : seedchoose = random . choice elif label_rules == 'min2max' : seedchoose = np . min elif label_rules == 'max2min' : seedchoose = np . max else : raise Exception ( 'Set wrong parameter label_rules.' ) while len ( dif_connvex ) != 0 : seedpt = seedchoose ( tuple ( dif_connvex ) ) parcel_connvex = get_connvex ( seedpt , faces , labelmask = lbl_orig_mask , label = label ) connvex . update ( parcel_connvex ) dif_connvex = orig_maskset . difference ( connvex ) parcel_num += 1 parcel_mask = tools . make_lblmask_by_loc ( parcel_mask , tuple ( parcel_connvex ) , parcel_num ) print ( 'parcel number: {0}' . format ( parcel_num ) ) return parcel_mask
Use region growing method to cut discontinuous specific regions to parcels
Parameters:
Use region growing method to cut discontinuous specific regions to parcels Parameters :
"""
    Use region growing method to cut discontinuous specific regions to parcels

    Parameters:
    -----------
    orig_mask: original mask has a/several small parcel(s) with labels
    faces: relationship of connection
    label[int]: specific label of orig_mask that used to cut into parcels
    label_ruls[string]: 'random', arrange new label randomly
                        'min2max', arrange new label from minimum vertex to maximum vertex
                        'max2min', arrange new label from maxmum vertex to minimum vertex

    Returns:
    --------
    parcel_mask: parcel mask that generated from specific label of orig_mask

    Example:
    --------
    >>> parcel_mask = cutrg2parcels(orig_mask, faces, 1)
    """
orig_mask
faces
label
label_rules