11
11
import numpy as np
12
12
from numpy import ma
13
13
from numpy .testing import assert_array_equal
14
+ from PIL import Image
14
15
15
16
from matplotlib import (
16
17
colors , image as mimage , patches , pyplot as plt , style , rcParams )
@@ -219,27 +220,24 @@ def test_imshow_zoom(fig_test, fig_ref):
219
220
@check_figures_equal ()
220
221
def test_imshow_pil (fig_test , fig_ref ):
221
222
style .use ("default" )
222
- PIL = pytest .importorskip ("PIL" )
223
223
png_path = Path (__file__ ).parent / "baseline_images/pngsuite/basn3p04.png"
224
224
tiff_path = Path (__file__ ).parent / "baseline_images/test_image/uint16.tif"
225
225
axs = fig_test .subplots (2 )
226
- axs [0 ].imshow (PIL . Image .open (png_path ))
227
- axs [1 ].imshow (PIL . Image .open (tiff_path ))
226
+ axs [0 ].imshow (Image .open (png_path ))
227
+ axs [1 ].imshow (Image .open (tiff_path ))
228
228
axs = fig_ref .subplots (2 )
229
229
axs [0 ].imshow (plt .imread (png_path ))
230
230
axs [1 ].imshow (plt .imread (tiff_path ))
231
231
232
232
233
233
def test_imread_pil_uint16 ():
234
- pytest .importorskip ("PIL" )
235
234
img = plt .imread (os .path .join (os .path .dirname (__file__ ),
236
235
'baseline_images' , 'test_image' , 'uint16.tif' ))
237
236
assert img .dtype == np .uint16
238
237
assert np .sum (img ) == 134184960
239
238
240
239
241
240
def test_imread_fspath ():
242
- pytest .importorskip ("PIL" )
243
241
img = plt .imread (
244
242
Path (__file__ ).parent / 'baseline_images/test_image/uint16.tif' )
245
243
assert img .dtype == np .uint16
@@ -248,8 +246,6 @@ def test_imread_fspath():
248
246
249
247
@pytest .mark .parametrize ("fmt" , ["png" , "jpg" , "jpeg" , "tiff" ])
250
248
def test_imsave (fmt ):
251
- if fmt in ["jpg" , "jpeg" , "tiff" ]:
252
- pytest .importorskip ("PIL" )
253
249
has_alpha = fmt not in ["jpg" , "jpeg" ]
254
250
255
251
# The goal here is that the user can specify an output logical DPI
@@ -314,7 +310,6 @@ def test_imsave_color_alpha():
314
310
315
311
316
312
def test_imsave_pil_kwargs_png ():
317
- Image = pytest .importorskip ("PIL.Image" )
318
313
from PIL .PngImagePlugin import PngInfo
319
314
buf = io .BytesIO ()
320
315
pnginfo = PngInfo ()
@@ -326,7 +321,6 @@ def test_imsave_pil_kwargs_png():
326
321
327
322
328
323
def test_imsave_pil_kwargs_tiff ():
329
- Image = pytest .importorskip ("PIL.Image" )
330
324
from PIL .TiffTags import TAGS_V2 as TAGS
331
325
buf = io .BytesIO ()
332
326
pil_kwargs = {"description" : "test image" }
@@ -664,7 +658,6 @@ def test_nonuniformimage_setnorm():
664
658
665
659
666
660
def test_jpeg_2d ():
667
- Image = pytest .importorskip ('PIL.Image' )
668
661
# smoke test that mode-L pillow images work.
669
662
imd = np .ones ((10 , 10 ), dtype = 'uint8' )
670
663
for i in range (10 ):
@@ -676,8 +669,6 @@ def test_jpeg_2d():
676
669
677
670
678
671
def test_jpeg_alpha ():
679
- Image = pytest .importorskip ('PIL.Image' )
680
-
681
672
plt .figure (figsize = (1 , 1 ), dpi = 300 )
682
673
# Create an image that is all black, with a gradient from 0-1 in
683
674
# the alpha channel from left to right.
0 commit comments