Add image stack.

This commit is contained in:
Stefan van der Walt
2009-11-07 17:41:29 +02:00
parent 775ff607cf
commit c10f3a886c
2 changed files with 47 additions and 1 deletions
+30 -1
View File
@@ -1,6 +1,35 @@
__all__ = ['imread', 'imsave', 'imshow', 'show']
__all__ = ['imread', 'imsave', 'imshow', 'show', 'push', 'pop']
from scikits.image.io._plugins import call as call_plugin
import numpy as np
# Shared image queue
_image_stack = []
def push(img):
"""Push an image onto the shared image stack.
Parameters
----------
img : ndarray
Image to push.
"""
if not isinstance(img, np.ndarray):
raise ValueError("Can only push ndarrays to the image stack.")
_image_stack.append(img)
def pop():
"""Pop and image from the shared image stack.
Returns
-------
img : ndarray
Image popped from the stack.
"""
return _image_stack.pop()
def imread(fname, as_grey=False, dtype=None, plugin=None, flatten=None,
**plugin_args):
+17
View File
@@ -0,0 +1,17 @@
from numpy.testing import *
import numpy as np
import scikits.image.io as io
def test_stack_basic():
x = np.arange(12).reshape(3, 4)
io.push(x)
assert_array_equal(io.pop(), x)
@raises(ValueError)
def test_stack_non_array():
io.push([[1, 2, 3]])
if __name__ == "__main__":
run_module_suite()