surrogate_tests.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import unittest
  2. import numpy as np
  3. from skimage.transform import resize
  4. from cvdatasets.dataset.part.surrogate import SurrogateType
  5. class SurrogateTest(unittest.TestCase):
  6. def setUp(self):
  7. self.im = np.random.randn(300, 300, 3).astype(np.uint8)
  8. def test_middle_surrogate(self):
  9. w = h = 100
  10. should = self.im[100:200, 100:200]
  11. computed = SurrogateType.MIDDLE(self.im, w, h)
  12. self.assertEqual(should.shape, computed.shape)
  13. self.assertTrue(np.all(should == computed))
  14. def test_blank_surrogate(self):
  15. w = h = 100
  16. should = np.zeros((h,w,3), dtype=np.uint8)
  17. computed = SurrogateType.BLANK(self.im, w, h)
  18. self.assertEqual(should.shape, computed.shape)
  19. self.assertTrue(np.all(should == computed))
  20. def test_image_surrogate(self):
  21. w = h = 100
  22. should = resize(self.im, (h, w),
  23. mode="constant",
  24. anti_aliasing=True,
  25. preserve_range=True).astype(np.uint8)
  26. computed = SurrogateType.IMAGE(self.im, w, h)
  27. self.assertEqual(should.shape, computed.shape)
  28. self.assertTrue(np.all(should == computed))