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.

129 lines
3.6 KiB

  1. # -*- coding: utf-8 -*-
  2. import numpy as np
  3. class Image(np.ndarray):
  4. """
  5. Holds the raw pixel data of an image and provides access to some metadata.
  6. """
  7. def __new__(cls, array):
  8. return np.asarray(array).view(cls)
  9. def __init__(self, array):
  10. self._index = None
  11. self._timestamp = None
  12. self._frame_number = None
  13. self._field_of_view = None
  14. self._channel = None
  15. self._z_level = None
  16. def add_params(self, index, timestamp, frame_number, field_of_view, channel, z_level):
  17. """
  18. :param index: The integer that can be used to directly index this image
  19. :type index: int
  20. :param timestamp: The number of milliseconds after the beginning of the acquisition that this image was taken.
  21. :type timestamp: float
  22. :param frame_number: The order in which this image was taken, with images of different channels/z-levels
  23. at the same field of view treated as being in the same frame.
  24. :type frame_number: int
  25. :param field_of_view: The label for the place in the XY-plane where this image was taken.
  26. :type field_of_view: int
  27. :param channel: The name of the color of this image
  28. :type channel: str
  29. :param z_level: The label for the location in the Z-plane where this image was taken.
  30. :type z_level: int
  31. """
  32. self._index = index
  33. self._timestamp = timestamp
  34. self._frame_number = int(frame_number)
  35. self._field_of_view = field_of_view
  36. self._channel = channel
  37. self._z_level = z_level
  38. @property
  39. def index(self):
  40. return self._index
  41. @property
  42. def height(self):
  43. """
  44. The height in pixels.
  45. :rtype: int
  46. """
  47. return self.shape[0]
  48. @property
  49. def width(self):
  50. """
  51. The width in pixels.
  52. :rtype: int
  53. """
  54. return self.shape[1]
  55. @property
  56. def field_of_view(self):
  57. """
  58. The index of the stage location where this image was acquired.
  59. :rtype: int
  60. """
  61. return self._field_of_view
  62. @property
  63. def timestamp(self):
  64. """
  65. The number of seconds after the beginning of the acquisition that the image was taken. Note that for a given
  66. field of view and z-level offset, if you have images of multiple channels, they will all be given the same
  67. timestamp. That's just how ND2s are structured, so if your experiment depends on millisecond accuracy,
  68. you need to find an alternative imaging system.
  69. :rtype: float
  70. """
  71. # data is actually stored in milliseconds
  72. return self._timestamp / 1000.0
  73. @property
  74. def frame_number(self):
  75. """
  76. The index of the group of images taken sequentially that all have the same group number and field of view.
  77. :rtype: int
  78. """
  79. return self._frame_number
  80. @property
  81. def channel(self):
  82. """
  83. The name of the filter used to acquire this image. These are user-supplied in NIS Elements.
  84. :rtype: str
  85. """
  86. return self._channel
  87. @property
  88. def z_level(self):
  89. """
  90. The vertical offset of the image. These are simple integers starting from 0, where the 0 is the lowest
  91. z-level and each subsequent level incremented by 1.
  92. For example, if you acquired images at -3 µm, 0 µm, and +3 µm, your z-levels would be:
  93. -3 µm: 0
  94. 0 µm: 1
  95. +3 µm: 2
  96. :rtype: int
  97. """
  98. return self._z_level