def post_process_image(img):
    """See instant-ngp/scripts/common.py
    write_image(file, img, quality=95)
    write_image_imageio(img_file, img, quality)
    """

    # See: write_image(file, img, quality=95)
    if img.shape[2] == 4:
        img = np.copy(img)
        # Unmultiply alpha
        img[..., 0:3] = np.divide(
            img[..., 0:3],
            img[..., 3:4],
            out=np.zeros_like(img[..., 0:3]),
            where=img[..., 3:4] != 0,
        )
        img[..., 0:3] = linear_to_srgb(img[..., 0:3])
    else:
        img = linear_to_srgb(img)

    # # See: write_image_imageio(img_file, img, quality)
    # img = (np.clip(img, 0.0, 1.0) * 255.0 + 0.5).astype(np.uint8)

    return img
See instant-ngp/scripts/common.py
    write_image(file, img, quality=95)
    write_image_imageio(img_file, img, quality)
    
example_view_synthesis_scripts/instant_ngp.py