You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.0 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. import numpy as np
  2. import logging
  3. log = logging.getLogger(__name__)
  4. class ImageSet(object):
  5. """
  6. A group of images that share the same timestamp. NIS Elements doesn't store a unique timestamp for every
  7. image, rather, it stores one for each set of images that share the same field of view and z-axis level.
  8. """
  9. def __init__(self):
  10. self._images = []
  11. def add(self, image):
  12. """
  13. :type image: nd2reader.model.Image()
  14. """
  15. self._images.append(image)
  16. def __iter__(self):
  17. for image in self._images:
  18. yield image
  19. class Image(object):
  20. def __init__(self, timestamp, raw_array, field_of_view, channel, z_level, height, width):
  21. self._timestamp = timestamp
  22. self._raw_data = raw_array
  23. self._field_of_view = field_of_view
  24. self._channel = channel
  25. self._z_level = z_level
  26. self._height = height
  27. self._width = width
  28. self._data = None
  29. @property
  30. def field_of_view(self):
  31. return self._field_of_view
  32. @property
  33. def timestamp(self):
  34. """
  35. The number of seconds after the beginning of the acquisition that the image was taken. Note that for a given field
  36. of view and z-level offset, if you have images of multiple channels, they will all be given the same timestamp.
  37. No, this doesn't make much sense. But that's how ND2s are structured, so if your experiment depends on millisecond
  38. accuracy, you need to find an alternative imaging system.
  39. """
  40. return self._timestamp / 1000.0
  41. @property
  42. def channel(self):
  43. return self._channel
  44. @property
  45. def z_level(self):
  46. return self._z_level
  47. @property
  48. def data(self):
  49. if self._data is None:
  50. # The data is just a flat, 1-dimensional array. We convert it to a 2D image here.
  51. self._data = np.reshape(self._raw_data, (self._height, self._width))
  52. return self._data
  53. @property
  54. def is_valid(self):
  55. return np.any(self._raw_data)