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')
评论列表
文章目录