mirror of
https://github.com/wassname/scikit-image.git
synced 2026-06-29 22:34:37 +08:00
Removed obsolete Image class from io submodule.
This commit is contained in:
+1
-47
@@ -11,53 +11,7 @@ from ..exposure import is_low_contrast
|
||||
from .._shared._warnings import all_warnings
|
||||
|
||||
|
||||
__all__ = ['Image', 'imread', 'imread_collection', 'imsave', 'imshow', 'show']
|
||||
|
||||
|
||||
class Image(np.ndarray):
|
||||
"""Class representing Image data.
|
||||
|
||||
These objects have tags for image metadata and IPython display protocol
|
||||
methods for image display.
|
||||
|
||||
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.
|
||||
|
||||
"""
|
||||
x = np.asarray(arr).view(cls)
|
||||
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')
|
||||
|
||||
def _repr_jpeg_(self):
|
||||
return self._repr_image_format('jpeg')
|
||||
|
||||
def _repr_image_format(self, format_str):
|
||||
str_buffer = BytesIO()
|
||||
imsave(str_buffer, self, format_str=format_str)
|
||||
return_str = str_buffer.getvalue()
|
||||
str_buffer.close()
|
||||
return return_str
|
||||
__all__ = ['imread', 'imread_collection', 'imsave', 'imshow', 'show']
|
||||
|
||||
|
||||
def imread(fname, as_grey=False, plugin=None, flatten=None,
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
from io import BytesIO
|
||||
|
||||
import numpy as np
|
||||
from skimage import img_as_ubyte
|
||||
from skimage.io import Image, imread
|
||||
|
||||
from numpy.testing import assert_equal, assert_array_equal
|
||||
|
||||
|
||||
def test_tags():
|
||||
f = Image([1, 2, 3], foo='bar', sigma='delta')
|
||||
g = Image([3, 2, 1], sun='moon')
|
||||
h = Image([1, 1, 1])
|
||||
|
||||
assert_equal(f.tags['foo'], 'bar')
|
||||
assert_array_equal((g + 2).tags['sun'], 'moon')
|
||||
assert_equal(h.tags, {})
|
||||
|
||||
|
||||
def test_repr_png_roundtrip():
|
||||
# Use RGB-like shape since some backends convert grayscale to RGB
|
||||
original_array = 255 * np.ones((5, 5, 3), dtype=np.uint8)
|
||||
image = Image(original_array)
|
||||
array = imread(BytesIO(image._repr_png_()))
|
||||
# Force output to ubyte range for plugin compatibility.
|
||||
# For example, Matplotlib will return floats even if the image is uint8.
|
||||
assert_array_equal(img_as_ubyte(array), original_array)
|
||||
# Note that PIL breaks with `_repr_jpeg_`.
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from numpy.testing import run_module_suite
|
||||
run_module_suite()
|
||||
@@ -7,8 +7,7 @@ from numpy.testing import (
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
from ... import data_dir
|
||||
from .. import (imread, imsave, use_plugin, reset_plugins,
|
||||
Image as ioImage)
|
||||
from .. import imread, imsave, use_plugin, reset_plugins
|
||||
from ..._shared.testing import mono_check, color_check
|
||||
from ..._shared._warnings import expected_warnings
|
||||
from ..._shared._tempfile import temporary_file
|
||||
@@ -80,19 +79,6 @@ def test_imread_uint16():
|
||||
assert_array_almost_equal(img, expected)
|
||||
|
||||
|
||||
def test_repr_png():
|
||||
img_path = os.path.join(data_dir, 'camera.png')
|
||||
original_img = ioImage(imread(img_path))
|
||||
original_img_str = original_img._repr_png_()
|
||||
|
||||
with NamedTemporaryFile(suffix='.png') as temp_png:
|
||||
temp_png.write(original_img_str)
|
||||
temp_png.seek(0)
|
||||
round_trip = imread(temp_png)
|
||||
|
||||
assert np.all(original_img == round_trip)
|
||||
|
||||
|
||||
def test_imread_truncated_jpg():
|
||||
assert_raises((IOError, ValueError), imread,
|
||||
os.path.join(data_dir, 'truncated.jpg'))
|
||||
|
||||
Reference in New Issue
Block a user