Allow keyword arguments to imread

This commit is contained in:
Steven Silvester
2014-10-24 13:24:42 -05:00
committed by Stefan van der Walt
parent 502f6af481
commit 0d76827734
2 changed files with 17 additions and 8 deletions
+6 -2
View File
@@ -9,7 +9,7 @@ from skimage.external.tifffile import (
imread as tif_imread, imsave as tif_imsave)
def imread(fname, dtype=None, img_num=None):
def imread(fname, dtype=None, img_num=None, **kwargs):
"""Load an image from file.
Parameters
@@ -21,6 +21,9 @@ def imread(fname, dtype=None, img_num=None):
img_num : int, optional
Specifies which image to read in a file with multiple images
(zero-indexed).
kwargs : keyword pairs, optional
Addition keyword arguments to pass through (only applicable to Tiff
files for now. See `tifffile`'s `imread` function.
Notes
-----
@@ -37,8 +40,9 @@ def imread(fname, dtype=None, img_num=None):
"""
if hasattr(fname, 'lower') and dtype is None:
kwargs.setdefault('key', img_num)
if fname.lower().endswith(('.tiff', '.tif')):
return tif_imread(fname, key=img_num)
return tif_imread(fname, **kwargs)
im = Image.open(fname)
try:
+11 -6
View File
@@ -152,7 +152,8 @@ class ImageCollection(object):
"""
def __init__(self, load_pattern, conserve_memory=True, load_func=None):
def __init__(self, load_pattern, conserve_memory=True, load_func=None,
**load_func_kwargs):
"""Load and manage a collection of images."""
if isinstance(load_pattern, six.string_types):
load_pattern = load_pattern.split(os.pathsep)
@@ -180,6 +181,8 @@ class ImageCollection(object):
else:
self.load_func = load_func
self.load_func_kwargs = load_func_kwargs
self.data = np.empty(memory_slots, dtype=object)
@property
@@ -248,10 +251,11 @@ class ImageCollection(object):
(self.data[idx] is None)):
if self._frame_index:
fname, img_num = self._frame_index[idx]
print('loading function')
self.data[idx] = self.load_func(fname, img_num=img_num)
self.data[idx] = self.load_func(fname, img_num=img_num,
**self.load_func_kwargs)
else:
self.data[idx] = self.load_func(self.files[n])
self.data[idx] = self.load_func(self.files[n],
**self.load_func_kwargs)
self._cached = n
return self.data[idx]
@@ -399,7 +403,8 @@ class MultiImage(ImageCollection):
"""
def __init__(self, filename, conserve_memory=True, dtype=None):
def __init__(self, filename, conserve_memory=True, dtype=None,
**imread_kwargs):
"""Load a multi-img."""
from ._io import imread
@@ -409,7 +414,7 @@ class MultiImage(ImageCollection):
self._filename = filename
super(MultiImage, self).__init__(filename, conserve_memory,
load_func=load_func)
load_func=load_func, **imread_kwargs)
@property
def filename(self):