mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-07 11:28:14 +08:00
Test Image._repr_png_
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
from skimage.io import Image
|
||||
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')
|
||||
@@ -11,7 +16,17 @@ def test_tags():
|
||||
assert_array_equal((g + 2).tags['sun'], 'moon')
|
||||
assert_equal(h.tags, {})
|
||||
|
||||
|
||||
def test_repr_png_roundtrip():
|
||||
original_array = 255 * np.ones((3, 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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user