util.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:vizgen 作者: uva-graphics 项目源码 文件源码
def write_img(out_img, out_filename, do_clip=True):
    """Writes out_img to out_filename
    """
    if use_4channel and len(out_img.shape) == 3 and out_img.shape[2] == 4:
        out_img = out_img[:,:,:3]

    assert out_img is not None, 'expected out_img to not be None'
    out_img = numpy.clip(out_img, 0, 1) if do_clip else out_img
    if is_pypy:
        out_img = numpy.asarray(out_img*255, 'uint8')
        if len(out_img.shape) == 2:
            mode = 'L'
        elif len(out_img.shape) == 3:
            if out_img.shape[2] == 3:
                mode = 'RGB'
            elif out_img.shape[2] == 4:
                mode = 'RGBA'
            else:
                raise ValueError('unknown color image mode')
        else:
            raise ValueError('unknown number of dimensions for image')

        I = Image.frombytes(mode, (out_img.shape[1], out_img.shape[0]), out_img.tobytes())
        I.save(out_filename)
    else:
        try:
            skimage.io.imsave(out_filename, out_img)
        except:
            print('Caught exception while saving to {}: image shape is {}, min: {}, max: {}'.format(out_filename, out_img.shape, out_img.min(), out_img.max()))
            raise
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号