test_tiffio.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import unittest
  2. import os
  3. from PIL import Image
  4. import numpy as np
  5. import shutil
  6. from neo.io.tiffio import TiffIO
  7. import quantities as pq
  8. class TestTiffIO(unittest.TestCase):
  9. def test_read_group_of_tiff_grayscale(self):
  10. directory = 'test_tiff'
  11. if not os.path.exists(directory):
  12. os.makedirs(directory)
  13. # directory is live
  14. img = []
  15. for picture in range(10):
  16. img.append([])
  17. for y in range(50):
  18. img[picture].append([])
  19. for x in range(50):
  20. img[picture][y].append(x)
  21. img = np.array(img, dtype=float)
  22. for image in range(10):
  23. Image.fromarray(img[image]).save(directory+'/tiff_exemple'+str(image)+".tif")
  24. ioclass = TiffIO(directory_path=directory, units='V', sampling_rate=1.0*pq.Hz,
  25. spatial_scale=1.0*pq.micrometer)
  26. blck = ioclass.read_block()
  27. self.assertEqual(len(blck.segments), 1)
  28. self.assertEqual(len(blck.segments[0].imagesequences), 1)
  29. self.assertEqual(blck.segments[0].imagesequences[0].any(), img.any())
  30. self.assertEqual(blck.segments[0].imagesequences[0].sampling_rate, 1.0*pq.Hz)
  31. self.assertEqual(blck.segments[0].imagesequences[0].spatial_scale, 1.0 * pq.micrometer)
  32. # end of directory
  33. shutil.rmtree(directory)
  34. if __name__ == "__main__":
  35. unittest.main()