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.

37 lines
979 B

  1. import collections
  2. class ImageGroup(object):
  3. """
  4. A group of images that were taken at roughly the same time and in the same field of view.
  5. """
  6. def __init__(self):
  7. self._images = collections.defaultdict(dict)
  8. def __len__(self):
  9. """ The number of images in the image set. """
  10. return sum([len(channel) for channel in self._images.values()])
  11. def __repr__(self):
  12. return "\n".join(["<ND2 Image Group>",
  13. "Image count: %s" % len(self)])
  14. def get(self, channel, z_level=0):
  15. """
  16. Retrieve an image with a given channel and z-level. For most users, z_level will always be 0.
  17. :type channel: str
  18. :type z_level: int
  19. """
  20. return self._images.get(channel).get(z_level)
  21. def add(self, image):
  22. """
  23. Stores an image.
  24. :type image: nd2reader.model.Image()
  25. """
  26. self._images[image.channel][image.z_level] = image