test_image.py 882 B

12345678910111213141516171819202122232425262728293031
  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, "annotated_with_data/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)
  17. def test_img_data_to_png_data():
  18. img_file = osp.join(data_dir, "annotated_with_data/apc2016_obj3.jpg")
  19. with open(img_file, "rb") as f:
  20. img_data = f.read()
  21. png_data = image_module.img_data_to_png_data(img_data)
  22. assert isinstance(png_data, bytes)