segmentation_functions.py
def index_to_RGB(mask_index, RGB_markers=None):
    """Change index to 2D image; each index corresponds to one color"""
    mask_index_copy = mask_index.copy()
    mask_index_copy = np.squeeze(mask_index_copy)  # In case the mask shape is not [height, width]
    if RGB_markers == None:
        print("RGB_markers not provided!")
        RGB_markers = [[255, 255, 255]]
    RGB_img = np.zeros((np.shape(mask_index_copy)[0], np.shape(mask_index_copy)[1], 3), dtype=np.uint8)
    RGB_img[:, :] = RGB_markers[0]  # Background
    for i in range(np.shape(RGB_markers)[0]):
        RGB_img[mask_index_copy == i] = RGB_markers[i]
    return RGB_img
Change index to 2D image; each index corresponds to one color
Change index to 2D image; each index corresponds to one color
Change index to 2D image ; each index corresponds to one color
def index_to_RGB(mask_index, RGB_markers=None):
    mask_index_copy = mask_index.copy()
    mask_index_copy = np.squeeze(mask_index_copy)  
    if RGB_markers == None:
        print("RGB_markers not provided!")
        RGB_markers = [[255, 255, 255]]
    RGB_img = np.zeros((np.shape(mask_index_copy)[0], np.shape(mask_index_copy)[1], 3), dtype=np.uint8)
    RGB_img[:, :] = RGB_markers[0]  
    for i in range(np.shape(RGB_markers)[0]):
        RGB_img[mask_index_copy == i] = RGB_markers[i]
    return RGB_img
def index_to_RGB ( mask_index , RGB_markers = None ) : mask_index_copy = mask_index . copy ( ) mask_index_copy = np . squeeze ( mask_index_copy ) if RGB_markers == None : print ( "RGB_markers not provided!" ) RGB_markers = [ [ 255 , 255 , 255 ] ] RGB_img = np . zeros ( ( np . shape ( mask_index_copy ) [ 0 ] , np . shape ( mask_index_copy ) [ 1 ] , 3 ) , dtype = np . uint8 ) RGB_img [ : , : ] = RGB_markers [ 0 ] for i in range ( np . shape ( RGB_markers ) [ 0 ] ) : RGB_img [ mask_index_copy == i ] = RGB_markers [ i ] return RGB_img
Change index to 2D image; each index corresponds to one color
Change index to 2D image ; each index corresponds to one color
"""Change index to 2D image; each index corresponds to one color""" # In case the mask shape is not [height, width] # Background
mask_index
RGB_markers