From 2b0f037422c07274bb3005321e474e2b8ceafddd Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Wed, 21 Aug 2013 17:46:38 +0200 Subject: [PATCH] Remove Image wrapper from io. Improve tags handling. --- doc/source/api_changes.txt | 11 +++++++--- skimage/io/_io.py | 33 +++++++++++++++++------------ skimage/io/tests/test_collection.py | 2 +- skimage/io/tests/test_pil.py | 5 +++-- 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/doc/source/api_changes.txt b/doc/source/api_changes.txt index 57486723..c363288d 100644 --- a/doc/source/api_changes.txt +++ b/doc/source/api_changes.txt @@ -1,9 +1,14 @@ +Version 0.9 +----------- +- No longer wrap ``imread`` output in an ``Image`` class. + +Version 0.4 +----------- +- Switch mask and radius arguments for ``median_filter`` + Version 0.3 ----------- - Remove ``as_grey``, ``dtype`` keyword from ImageCollection - Remove ``dtype`` from imread - Generalise ImageCollection to accept a load_func -Version 0.4 ------------ -- Switch mask and radius arguments for median_filter diff --git a/skimage/io/_io.py b/skimage/io/_io.py index 63d3d7e4..a7df4694 100644 --- a/skimage/io/_io.py +++ b/skimage/io/_io.py @@ -35,28 +35,33 @@ class Image(np.ndarray): These objects have tags for image metadata and IPython display protocol methods for image display. - """ - tags = {'filename': '', - 'EXIF': {}, - 'info': {}} + Parameters + ---------- + arr : ndarray + Image data. + kwargs : Image tags as keywords + Specified in the form ``tag0=value``, ``tag1=value``. + + Attributes + ---------- + tags : dict + Meta-data. + + """ def __new__(cls, arr, **kwargs): """Set the image data and tags according to given parameters. - Parameters - ---------- - arr : ndarray - Image data. - kwargs : Image tags as keywords - Specified in the form ``tag0=value``, ``tag1=value``. - """ x = np.asarray(arr).view(cls) - for tag, value in Image.tags.items(): - setattr(x, tag, kwargs.get(tag, getattr(arr, tag, value))) + x.tags = kwargs + return x + def __array_finalize__(self, obj): + self.tags = getattr(obj, 'tags', {}) + def _repr_png_(self): return self._repr_image_format('png') @@ -147,7 +152,7 @@ def imread(fname, as_grey=False, plugin=None, flatten=None, if as_grey and getattr(img, 'ndim', 0) >= 3: img = rgb2grey(img) - return Image(img) + return img def imread_collection(load_pattern, conserve_memory=True, diff --git a/skimage/io/tests/test_collection.py b/skimage/io/tests/test_collection.py index 25cd1152..f56d753b 100644 --- a/skimage/io/tests/test_collection.py +++ b/skimage/io/tests/test_collection.py @@ -57,7 +57,7 @@ class TestImageCollection(): def test_getitem(self): num = len(self.collection) for i in range(-num, num): - assert type(self.collection[i]) is ioImage + assert type(self.collection[i]) is np.ndarray assert_array_almost_equal(self.collection[0], self.collection[-num]) diff --git a/skimage/io/tests/test_pil.py b/skimage/io/tests/test_pil.py index 664bcf4d..61ec5ce3 100644 --- a/skimage/io/tests/test_pil.py +++ b/skimage/io/tests/test_pil.py @@ -6,7 +6,8 @@ from numpy.testing.decorators import skipif from tempfile import NamedTemporaryFile from skimage import data_dir -from skimage.io import imread, imsave, use_plugin, reset_plugins +from skimage.io import (imread, imsave, use_plugin, reset_plugins, + Image as ioImage) from skimage._shared.six.moves import StringIO @@ -83,7 +84,7 @@ def test_imread_uint16(): @skipif(not PIL_available) def test_repr_png(): img_path = os.path.join(data_dir, 'camera.png') - original_img = imread(img_path) + original_img = ioImage(imread(img_path)) original_img_str = original_img._repr_png_() with NamedTemporaryFile(suffix='.png') as temp_png: