mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-03 13:11:25 +08:00
Add image stack.
This commit is contained in:
+30
-1
@@ -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):
|
||||
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user