Remove Image wrapper from io. Improve tags handling.

This commit is contained in:
Stefan van der Walt
2013-08-21 17:46:38 +02:00
parent 9a5a767ce8
commit 2b0f037422
4 changed files with 31 additions and 20 deletions
+8 -3
View File
@@ -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
+19 -14
View File
@@ -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,
+1 -1
View File
@@ -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])
+3 -2
View File
@@ -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: