segmentation_functions.py
def RGB_to_index(RGB_img, RGB_markers=None, RGB_labels=None):
    """Change RGB to 2D index matrix; each RGB color corresponds to one index.
    
    Args:
        RGB_markers: start from background (marked as 0); 
            Example format:
                [[255, 255, 255],
                [160, 255, 0]]
        RGB_labels: a numeric vector corresponding to the labels of RGB_markers; 
            length should be the same as RGB_markers.
    """
    if np.shape(RGB_img)[2] is not 3:
        print("Not an RGB image")
        return RGB_img
    else:
        if RGB_markers == None:
            RGB_markers = [[255, 255, 255]]
        if RGB_labels == None:
            RGB_labels = range(np.shape(RGB_markers)[0])
        mask_index = np.zeros((np.shape(RGB_img)[0], np.shape(RGB_img)[1]))
        for i, RGB_label in enumerate(RGB_labels):
            mask_index[np.all(RGB_img == RGB_markers[i], axis=2)] = RGB_label
    return mask_index
Change RGB to 2D index matrix; each RGB color corresponds to one index.
    
    Args:
        RGB_markers: start from background (marked as 0); 
            Example format:
                [[255, 255, 255],
                [160, 255, 0]]
        RGB_labels: a numeric vector corresponding to the labels of RGB_markers; 
            length should be the same as RGB_markers.
    
Change RGB to 2D index matrix; each RGB color corresponds to one index.
Change RGB to 2D index matrix ; each RGB color corresponds to one index .
def RGB_to_index(RGB_img, RGB_markers=None, RGB_labels=None):
    if np.shape(RGB_img)[2] is not 3:
        print("Not an RGB image")
        return RGB_img
    else:
        if RGB_markers == None:
            RGB_markers = [[255, 255, 255]]
        if RGB_labels == None:
            RGB_labels = range(np.shape(RGB_markers)[0])
        mask_index = np.zeros((np.shape(RGB_img)[0], np.shape(RGB_img)[1]))
        for i, RGB_label in enumerate(RGB_labels):
            mask_index[np.all(RGB_img == RGB_markers[i], axis=2)] = RGB_label
    return mask_index
def RGB_to_index ( RGB_img , RGB_markers = None , RGB_labels = None ) : if np . shape ( RGB_img ) [ 2 ] is not 3 : print ( "Not an RGB image" ) return RGB_img else : if RGB_markers == None : RGB_markers = [ [ 255 , 255 , 255 ] ] if RGB_labels == None : RGB_labels = range ( np . shape ( RGB_markers ) [ 0 ] ) mask_index = np . zeros ( ( np . shape ( RGB_img ) [ 0 ] , np . shape ( RGB_img ) [ 1 ] ) ) for i , RGB_label in enumerate ( RGB_labels ) : mask_index [ np . all ( RGB_img == RGB_markers [ i ] , axis = 2 ) ] = RGB_label return mask_index
Change RGB to 2D index matrix; each RGB color corresponds to one index.
Change RGB to 2D index matrix ; each RGB color corresponds to one index .
"""Change RGB to 2D index matrix; each RGB color corresponds to one index.
    
    Args:
        RGB_markers: start from background (marked as 0); 
            Example format:
                [[255, 255, 255],
                [160, 255, 0]]
        RGB_labels: a numeric vector corresponding to the labels of RGB_markers; 
            length should be the same as RGB_markers.
    """
RGB_img
RGB_markers
None
RGB_labels
a numeric vector corresponding to the labels of RGB_markers;
length should be the same as RGB_markers.
a numeric vector corresponding to the labels of RGB_markers ; length should be the same as RGB_markers .