test_imageutil.py 文件源码

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

项目:nuts-ml 作者: maet3608 项目源码 文件源码
def test_pil_to_arr():
    rgb_arr = np.ones((5, 4, 3), dtype='uint8')
    pil_img = ni.arr_to_pil(rgb_arr)
    arr = ni.pil_to_arr(pil_img)
    nt.assert_allclose(rgb_arr, arr)
    assert arr.dtype == np.uint8

    gray_arr = np.ones((5, 4), dtype='uint8')
    pil_img = ni.arr_to_pil(gray_arr)
    arr = ni.pil_to_arr(pil_img)
    nt.assert_allclose(gray_arr, arr)
    assert arr.dtype == np.uint8

    with pytest.raises(ValueError) as ex:
        rgb_arr = np.ones((5, 4, 3), dtype='uint8')
        hsv_img = pil.Image.fromarray(rgb_arr, 'HSV')
        ni.pil_to_arr(hsv_img)
    assert str(ex.value).startswith('Expect RBG or grayscale but got')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号