def rescale(img, overwrite=False):
    """
    Rescale image intensities linearly to 0~255
    """
    if not overwrite:
        result = img.copy()
    else:
        result = img
    result = result.astype('float')
    result -= result.min()
    result /= result.max()
    result *= 255
    return result
