test_image.py 591 B

1234567891011121314151617181920212223
  1. import os.path as osp
  2. import numpy as np
  3. import PIL.Image
  4. from labelme.utils import image as image_module
  5. from .util import data_dir
  6. from .util import get_img_and_data
  7. def test_img_b64_to_arr():
  8. img, _ = get_img_and_data()
  9. assert img.dtype == np.uint8
  10. assert img.shape == (907, 1210, 3)
  11. def test_img_arr_to_b64():
  12. img_file = osp.join(data_dir, 'apc2016_obj3.jpg')
  13. img_arr = np.asarray(PIL.Image.open(img_file))
  14. img_b64 = image_module.img_arr_to_b64(img_arr)
  15. img_arr2 = image_module.img_b64_to_arr(img_b64)
  16. np.testing.assert_allclose(img_arr, img_arr2)