Add imshow to PIL plugin.

This commit is contained in:
Stefan van der Walt
2010-06-08 15:54:00 -06:00
parent 03b53f85e6
commit bd7a15ebaf
2 changed files with 16 additions and 1 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
[pil]
description = Image reading via the Python Imaging Library
provides = imread, imsave
provides = imread, imsave, imshow
+15
View File
@@ -92,3 +92,18 @@ def imsave(fname, arr):
img = Image.fromstring(mode, (arr.shape[1], arr.shape[0]), arr.tostring())
img.save(fname)
def imshow(arr):
"""Display an image, using PIL's default display command.
Parameters
----------
arr : ndarray
Image to display. Images of dtype float are assumed to be in
[0, 1]. Images of dtype uint8 are in [0, 255].
"""
if np.issubdtype(arr.dtype, float):
arr = (arr * 255).astype(np.uint8)
Image.fromarray(arr).show()