5
5
from matplotlib import rcParams
6
6
import matplotlib .pyplot as plt
7
7
from nose .tools import assert_raises
8
- from numpy .testing import assert_array_equal
8
+ from numpy .testing import assert_array_equal , assert_array_almost_equal
9
9
10
10
import io
11
11
import os
@@ -129,8 +129,9 @@ def test_imsave():
129
129
assert_array_equal (arr_dpi1 , arr_dpi100 )
130
130
131
131
def test_imsave_color_alpha ():
132
- # The goal is to test that imsave will accept arrays with ndim=3 where
133
- # the third dimension is color and alpha without raising any exceptions
132
+ # Test that imsave accept arrays with ndim=3 where the third dimension is
133
+ # color and alpha without raising any exceptions, and that the data is
134
+ # acceptably preserved through a save/read roundtrip.
134
135
from numpy import random
135
136
random .seed (1 )
136
137
data = random .rand (256 , 128 , 4 )
@@ -141,12 +142,14 @@ def test_imsave_color_alpha():
141
142
buff .seek (0 )
142
143
arr_buf = plt .imread (buff )
143
144
144
- assert arr_buf .shape == data .shape
145
+ # Recreate the float -> uint8 -> float32 conversion of the data
146
+ data = (255 * data ).astype ('uint8' ).astype ('float32' )/ 255
147
+ # Wherever alpha values were rounded down to 0, the rgb values all get set
148
+ # to 0 during imsave (this is reasonable behaviour).
149
+ # Recreate that here:
150
+ data [data [:, :, 3 ] == 0 ] = 0
145
151
146
- # Unfortunately, the AGG process "flattens" the RGBA data
147
- # into an equivalent RGB data with no transparency. So we
148
- # Can't directly compare the arrays like we could in some
149
- # other imsave tests.
152
+ assert_array_equal (data , arr_buf )
150
153
151
154
@image_comparison (baseline_images = ['image_clip' ])
152
155
def test_image_clip ():
0 commit comments