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.

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