_image_stack.py 570 B

1234567891011121314151617181920212223242526272829303132333435
  1. import numpy as np
  2. __all__ = ['image_stack', 'push', 'pop']
  3. # Shared image queue
  4. image_stack = []
  5. def push(img):
  6. """Push an image onto the shared image stack.
  7. Parameters
  8. ----------
  9. img : ndarray
  10. Image to push.
  11. """
  12. if not isinstance(img, np.ndarray):
  13. raise ValueError("Can only push ndarrays to the image stack.")
  14. image_stack.append(img)
  15. def pop():
  16. """Pop an image from the shared image stack.
  17. Returns
  18. -------
  19. img : ndarray
  20. Image popped from the stack.
  21. """
  22. return image_stack.pop()