diff --git a/scikits/image/io/io.py b/scikits/image/io/io.py index 66d3b82b..a2a431ac 100644 --- a/scikits/image/io/io.py +++ b/scikits/image/io/io.py @@ -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): diff --git a/scikits/image/io/tests/test_io.py b/scikits/image/io/tests/test_io.py new file mode 100644 index 00000000..dbf5a3fc --- /dev/null +++ b/scikits/image/io/tests/test_io.py @@ -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()