def replace_colors(segmentation, color_changes):
    """
    Replace the values in segmentation to the values defined in color_changes.

    Parameters
    ----------
    segmentation : numpy array
        Two dimensional
    color_changes : dict
        The key is the original color, the value is the color to change to.
        The key 'default' is used when the color is not in the dict.
        If default is not defined, no replacement is done.
        Each color has to be a tuple (r, g, b) with r, g, b in {0, 1, ..., 255}
    Returns
    -------
    np.array
        The new colored segmentation
    """
    width, height = segmentation.shape
    output = scipy.misc.toimage(segmentation)
    output = output.convert('RGBA')
    for x in range(0, width):
        for y in range(0, height):
            if segmentation[x, y] in color_changes:
                output.putpixel((y, x), color_changes[segmentation[x, y]])
            elif 'default' in color_changes:
                output.putpixel((y, x), color_changes['default'])
    return output

    Replace the values in segmentation to the values defined in color_changes.

    Parameters
    ----------
    segmentation : numpy array
        Two dimensional
    color_changes : dict
        The key is the original color, the value is the color to change to.
        The key 'default' is used when the color is not in the dict.
        If default is not defined, no replacement is done.
        Each color has to be a tuple (r, g, b) with r, g, b in {0, 1, ..., 255}
    Returns
    -------
    np.array
        The new colored segmentation
    
submodules/evaluation/overlay_utils.py