From b8c30bad4699e13a2c9a3eb055e11cf04990bae3 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Mon, 18 Nov 2013 21:15:04 -0600 Subject: [PATCH] Move image stack to its own module --- skimage/io/__init__.py | 1 + skimage/io/_image_stack.py | 35 +++++++++++++++++++++++++++++++++++ skimage/io/_io.py | 38 ++++---------------------------------- 3 files changed, 40 insertions(+), 34 deletions(-) create mode 100644 skimage/io/_image_stack.py diff --git a/skimage/io/__init__.py b/skimage/io/__init__.py index 5e701a51..a2553c54 100644 --- a/skimage/io/__init__.py +++ b/skimage/io/__init__.py @@ -14,6 +14,7 @@ from .sift import * from .collection import * from ._io import * +from ._image_stack import * from .video import * diff --git a/skimage/io/_image_stack.py b/skimage/io/_image_stack.py new file mode 100644 index 00000000..ca9896d5 --- /dev/null +++ b/skimage/io/_image_stack.py @@ -0,0 +1,35 @@ +import numpy as np + + +__all__ = ['image_stack', 'push', 'pop'] + + +# 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 an image from the shared image stack. + + Returns + ------- + img : ndarray + Image popped from the stack. + + """ + return image_stack.pop() diff --git a/skimage/io/_io.py b/skimage/io/_io.py index eb704a6f..ae05ea77 100644 --- a/skimage/io/_io.py +++ b/skimage/io/_io.py @@ -1,10 +1,7 @@ -__all__ = ['Image', 'imread', 'imread_collection', 'imsave', 'imshow', 'show', - 'push', 'pop'] - try: - from urllib.request import urlopen + from urllib.request import urlopen # Python 3 except ImportError: - from urllib2 import urlopen + from urllib2 import urlopen # Python 2 import os import re @@ -19,8 +16,8 @@ from skimage.color import rgb2grey -# Shared image queue -_image_stack = [] +__all__ = ['Image', 'imread', 'imread_collection', 'imsave', 'imshow', 'show'] + URL_REGEX = re.compile(r'http://|https://|ftp://|file://|file:\\') @@ -77,33 +74,6 @@ class Image(np.ndarray): return return_str -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 an image from the shared image stack. - - Returns - ------- - img : ndarray - Image popped from the stack. - - """ - return _image_stack.pop() - - def imread(fname, as_grey=False, plugin=None, flatten=None, **plugin_args): """Load an image from file.