From 137807c89626020c63695fc3707d896e9586ecfe Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Mon, 12 Dec 2011 17:25:08 -0800 Subject: [PATCH] Correctly load 16-bit images. --- lib/matplotlib/image.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 12711ec55370..82a805ca11f4 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -1255,10 +1255,10 @@ def pil_to_array( pilImage ): grayscale images, the return array is MxN. For RGB images, the return value is MxNx3. For RGBA images the return value is MxNx4 """ - def toarray(im): + def toarray(im, dtype=np.uint8): 'return a 1D array of floats' x_str = im.tostring('raw',im.mode,0,-1) - x = np.fromstring(x_str,np.uint8) + x = np.fromstring(x_str, dtype) return x if pilImage.mode in ('RGBA', 'RGBX'): @@ -1275,6 +1275,11 @@ def toarray(im): x = toarray(im) x.shape = im.size[1], im.size[0], 3 return x + elif pilImage.mode=='I;16': + im = pilImage + x = toarray(im, '>u2' if im.mode.endswith('B') else '