Move image stack to its own module

This commit is contained in:
Tony S Yu
2013-12-05 23:19:43 -06:00
parent cff007827c
commit b8c30bad46
3 changed files with 40 additions and 34 deletions
+1
View File
@@ -14,6 +14,7 @@ from .sift import *
from .collection import *
from ._io import *
from ._image_stack import *
from .video import *
+35
View File
@@ -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()
+4 -34
View File
@@ -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.