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.

105 lines
3.0 KiB

  1. # -*- coding: utf-8 -*-
  2. import numpy as np
  3. import warnings
  4. class Image(np.ndarray):
  5. def __new__(cls, array):
  6. return np.asarray(array).view(cls)
  7. def __init__(self, array):
  8. self._timestamp = None
  9. self._frame_number = None
  10. self._field_of_view = None
  11. self._channel = None
  12. self._z_level = None
  13. def add_params(self, timestamp, frame_number, field_of_view, channel, z_level):
  14. """
  15. A wrapper around the raw pixel data of an image.
  16. :param timestamp: The frame number relative to the .
  17. :type timestamp: int
  18. :param timestamp: The number of milliseconds after the beginning of the acquisition that this image was taken.
  19. :type timestamp: int
  20. :param field_of_view: The label for the place in the XY-plane where this image was taken.
  21. :type field_of_view: int
  22. :param channel: The name of the color of this image
  23. :type channel: str
  24. :param z_level: The label for the location in the Z-plane where this image was taken.
  25. :type z_level: int
  26. """
  27. self._timestamp = timestamp
  28. self._frame_number = int(frame_number)
  29. self._field_of_view = field_of_view
  30. self._channel = channel
  31. self._z_level = z_level
  32. @property
  33. def height(self):
  34. return self.shape[1]
  35. @property
  36. def width(self):
  37. return self.shape[0]
  38. @property
  39. def field_of_view(self):
  40. """
  41. Which of the fixed locations this image was taken at.
  42. :rtype int:
  43. """
  44. return self._field_of_view
  45. @property
  46. def timestamp(self):
  47. """
  48. The number of seconds after the beginning of the acquisition that the image was taken. Note that for a given
  49. field of view and z-level offset, if you have images of multiple channels, they will all be given the same
  50. timestamp. No, this doesn't make much sense. But that's how ND2s are structured, so if your experiment depends
  51. on millisecond accuracy, you need to find an alternative imaging system.
  52. :rtype float:
  53. """
  54. return self._timestamp / 1000.0
  55. @property
  56. def frame_number(self):
  57. return self._frame_number
  58. @property
  59. def channel(self):
  60. """
  61. The name of the filter used to acquire this image. These are user-supplied in NIS Elements.
  62. :rtype str:
  63. """
  64. return self._channel
  65. @property
  66. def z_level(self):
  67. """
  68. The vertical offset of the image. These are simple integers starting from 0, where the 0 is the lowest
  69. z-level and each subsequent level incremented by 1.
  70. For example, if you acquired images at -3 µm, 0 µm, and +3 µm, your z-levels would be:
  71. -3 µm: 0
  72. 0 µm: 1
  73. +3 µm: 2
  74. :rtype int:
  75. """
  76. return self._z_level
  77. @property
  78. def data(self):
  79. warnings.warn("Image objects now directly subclass Numpy arrays, so using the data attribute will be removed in the near future.", DeprecationWarning)
  80. return self